練習問題 解答
6.9 練習問題 解答
問1
① ○:if文以外にはswitch文もあります。
② ×:ifブロックの後にはelse if文を繋げることもできます。また、else文は省略可能です。
③ ○
④ ○
問2
① if(x <= 13)
② if(x > 99)
③ if(x == 7)
④ if(x >= -1)
⑤ if(x != 5)
⑥ if(x < 0)
問3
① 満たさない:x = -3 y = -4
② 満たさない:x = 3 y = 2
③ 満たさない:x = 3 y = 3
④ 満たす :x = 3 y = 4
xよりyが大きい値でないと条件は満たされないので、④のみが条件式を満たしています。
問4
➢ Practice0601.java
1 | package jp.co.f1.superintro.ch06exercise; |
3 | import java.util.Scanner; |
5 | public class Practice0601 { |
6 | public static void main(String[] args) { |
7 | Scanner sc = new Scanner(System.in); |
8 | System.out.print("数値を入力-->"); |
9 | int num = sc.nextInt(); |
12 | System.out.println("入力数値[" + num + "]は偶数です。"); |
14 | System.out.println("入力数値[" + num + "]は奇数です。"); |
NEXT>> 第7章 繰り返し処理