2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GoAdvent Calendar 2024

Day 2

Goで入出力

Posted at

概要

Go言語で、キーボードから文字の入力を受け付ける処理について

実行結果

次の日のテレワークのおやつを入力するプログラム

image.png

ソースコード

package main

import "fmt"

func main() {
	var input string
	for {
		fmt.Print("明日のテレワークおやつは何ですか。qキーで終了します:")
		fmt.Scanln(&input)

		if input == "q" {
			break
		}
		fmt.Println(input, "が入力されました")
	}
}

fmtパッケージのScanln関数を利用すると、キーボードからの入力を受け付けることができる

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?