私はいくつかの試験のスコアを入力して全体的に最高と最低のスコアを入力するよう質問しています。 (質問を強調した。) Javaで最高のスコア
float sum = 0, score1, score2 = 0, score3 = 0;
do
{
System.out.println("Enter a score [negative score to quit]: ");
Scanner Score1 = new Scanner(System.in);
score1 = Score1.nextFloat();
if (score1>score2)
{
max = score1;
min = score2;
}
else if(score1<score2)
{
max = score2;
min = score1;
}
else{
score3 = score2;
}
}
}
while (score1>=0);
System.out.printf("Minimun Score = %.0f\n", min);
System.out.printf("Maximum Score = %.0f\n", max);
Enter a score [negative score to quit]:
99
Enter a score [negative score to quit]:
1
Enter a score [negative score to quit]:
6
Enter a score [negative score to quit]:
5
Enter a score [negative score to quit]:
-1
Minimum Score = 5
Maximum Score = 6
BUILD SUCCESSFUL (total time: 7 seconds)
問題はそれだけで私が入力された最新の2得点を比較しています。 どうすれば修正できますか?
3つの変数がありますが、ユーザーは5つの値を入力します。おそらく1秒間これについて考えます。次に、配列に関するいくつかの研究を行います。それはあなたがここで使用すべきものですから。 – GhostCat
これは、毎回新しいスキャナオブジェクトを作成するためです。 –
スコア2を取り除き、常にあなたのスコアを1分と最大と比較してください。 – mlecz