合計が100+になるか、ユーザーが5つの数値を入力するまで、入力を追加するJavaプログラムを作成しようとしています。私はまた、最高の入力を追跡する最高の実行を追加しようとしています。現在のところ、合計が100未満で、最高ランが動作しない場合、5つの入力の後に実行を続けます。 ?私はこの問題を解決する方法をあなたが軌道に乗るためにプログラムは意図したとおりに実行されていません
import java.io.*;
public class HighScoreTest {
public static void main(String[] args) {
// input streams.
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
// constant declarations
final Integer MAX = 100;
final Integer MAX_NUMBER = 4;
// variable declarations
String sName;
Integer currentTotal;
Integer currentNumber;
Integer numbersInputed = 0;
Integer count;
Integer maxRunToDate = 0;
// we catch exceptions if some are thrown.
// an exception would be entering a string when a number is expected
try {
System.out.println("What is your name?");
// reading string from the stream
sName = reader.readLine();
currentTotal = 0;
for(count = 0; count < MAX_NUMBER; count++) {
numbersInputed += count;
}
do {
System.out.println("Please enter a number");
currentNumber = Integer.parseInt(reader.readLine());
currentTotal = currentTotal + currentNumber;
}while(currentTotal < MAX || numbersInputed == MAX_NUMBER);
if (maxRunToDate < currentTotal) {
maxRunToDate = currentTotal;
}
System.out.println(sName +", the total for this run is "+ currentTotal);
System.out.println("The highest run is "+ maxRunToDate);
} catch (IOException e){
System.out.println("Error reading from user");
}
}
}
問題を再現しながらできるだけプログラムを短くします。プログラム全体のデバッグを依頼しないでください。それを短縮したら、おそらく問題を見るか、もう一度聞くことができます。 –
ユーザが5つの数字を入力したい場合、なぜMAX_NUMBERが4に設定されていますか? – QBrute