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?

More than 3 years have passed since last update.

Java小テスト③ ~ while 編 〜

Last updated at Posted at 2021-02-28

これは友達向けのJavaの小テストです。
Java初心者の文法腕試しでお使いくださいー!!

今日はwhile文の小テストを作りたいと思います!

問題①:次のプログラムを10未満の偶数の数を出力するように訂正せよ。

while(i < 10) {
    System.out.println(i);
}

問題②:次の出力は何か?

public class WhileClass {
    public static void main(String[] args) {
       int i = 0;
       while(i < 10) {
           if(i % 3 == 0 && i % 5 == 0) {
               System.out.println("FizzBuzz");
           } else if(i % 3 == 0) {
               System.out.println("Fizz");
           } else if(i % 5 == 0) {
               System.out.println("Buzz");
           } else {
               System.out.println(i);
           }
           i++;
       }
    }
}

問題③:次の問題に答えよ

for文とwhile文はどのように使い分けるか?

問題④:以下を全て満たすプログラムをwhileを使って書け。

  • ユーザーに2つの数字の入力を求める。
  • 入力が数字でない場合は, 聞き直す。
  • 2つの数字を入力後
    • 操作の数字を入力してもらう。
      • 入力が0であれば, プログラムは終了
      • 入力が1であれば, 2つの数を足した値を返す
      • 入力が2であれば, 2つの数を引いた絶対値を返す。
      • 入力が3であれば, 2つの数をかけた数を返す。
      • 入力が4であれば, 大きい方から小さい方を割った数を返す。(ただし, 小さい数が0だった場合はエラーを出力)
      • (入力が5以上であれば, 数字を聞き直す。) ← 出来れば。
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?