ユーザーに、最大 5 までの任意の数字をスペースで区切って入力するように求めようとしています。
例えば
数字を 5 つまで入力してください: 3 4 5
それらを整数の合計に追加し、後でそれらをカウンターで割ります
これらの数値の平均を取得します。
しかし、私のループは終わっていないようです。コードの何が問題になっていますか?
int counter = 0 , sum = 0;
Scanner scan = new Scanner(System.in);
System.out.println("enter up to 5 numbers");
while(scan.hasNextInt());{
counter++;
sum += scan.nextInt();
}
System.out.println(counter);
System.out.println(sum);