0
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?

java 条件式とif文

Posted at

☆条件式の書き方☆

8a2c9b27375f4a946a97269c974a624b.png

☆if文☆
条件式の結果がtrueなら第一ブロック、falseなら第2ブロックを返す
if(分岐条件) {
条件成立のときに実行する処理
} else {
条件不成立のときに実行する処理
}

falseのとき、別の条件で分岐したいときは else if 使用

例)
System.out.println("年齢を入力してください");
int age = new java.util.Scanner(System.in).nextInt();
if (age <= 3) {
System.out.println("300円");
} else if ( age <= 12 ) {
System.out.println("500円");
} else {
System.out.println("1000円");
}

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?