LoginSignup
0
0

More than 3 years have passed since last update.

Java よく使う命令一覧(初心者、入門者向け)

Posted at

よく使う命令一覧

コメントアウト

// 1行ならスラッシュ2つ

/* 複数行なら
  スラッシュと
  アスタリスクで囲む
*/

キーボードから1行の文字列を受け取る

// 入力した文字列を変数wordsに代入
String words = new java.util.Scanner(System.in).nextLine();

キーボードから1つの整数を受け取る

// 入力した整数を変数valueに代入
int value = new java.util.Scanner(System.in).nextInt();

文字列を表示(改行あり)

System.out.println("表示する文字列");

文字列を表示(改行なし)

System.out.print("表示する文字列");

文字列を整数に変換

int n = Integer.parseInt(stringNumber);

例:文字列の1, 2を整数に変換して足し算する

String s_1 = "1";
String s_2 = "2";

//文字列のまま足す -> 12が出力される
System.out.println(s_1 + s_2);

//整数に変換
int i_1 = Integer.parseInt(s_1);
int i_2 = Integer.parseInt(s_2);

//整数に変換してから足す -> 3が出力される
System.out.println(i_1 + i_2);
<実行結果>
12
3
0
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
0
0