怪獣:
私は、彼らが次のステップにプログラムを継続するために値を入力するまでの整数をユーザに促しプログラムを持っています。どのように私は変数は、ユーザが整数を入力するたびにカウントと呼ばれるインクリメントでしょうか?私は単なるデータではときにユーザープットそれが上がるようにする方法がわからない、途中でカウント量をインクリメントする++のカウントを使用しています。
コードのこれまで
//variables
int num, count = 0, high, low;
Scanner userInput = new Scanner(System.in);
//loop
do {
System.out.print("Enter an integer, or -99 to quit: --> ");
num = userInput.nextInt();
high = num;
low = num;
//higher or lower
if(count > 0 && num > high)
{
high = num;
}
else if(count > 0 && num < low)
{
low = num;
}
else
{
System.out.println("You did not enter any numbers.");
}
} while (num != -99);
System.out.println("Largest integer entered: " + high);
System.out.println("Smallest integer entered: " + low);
Hasitha Jayawardana:
簡単だ。ジャストは入れcount++
内側にwhile loop
次のように、
// variables
int num, count = 0, high, low;
Scanner userInput = new Scanner(System.in);
// loop
do {
System.out.print("Enter an integer, or -99 to quit: --> ");
num = userInput.nextInt();
count++; // here it goes
high = num;
low = num;
// higher or lower
if(count > 0 && num > high)
{
high = num;
}
else if(count > 0 && num < low)
{
low = num;
}
else
{
System.out.println("You did not enter any numbers.");
}
} while (num != -99);
System.out.println("Largest integer entered: " + high);
System.out.println("Smallest integer entered: " + low);