私はJavaが初めてで、答えに非常に近いです。完全な答えではなく、いくつかのヒントが得られることを願っています。自分でロジックを導き出すことを好みます。
/*
Write a method named makeGuesses that will guess numbers
between 1 and 50 inclusive until it makes a guess of at least 48.
It should report each guess and at the end should report
the total number of guesses made. Below is a sample execution:
*/
guess = 43
guess = 47
guess = 45
guess = 27
guess = 49
total guesses = 5
public void makeGuesses(){
Scanner sc=new Scanner(System.in);
Random rnd=new Random();
int i=1
int counter=0;
while(i>=1 && i<=50){
i=rnd.nextInt();
System.out.println("guess = " + i);
counter++;
}
System.out.print("total guesses = "+ counter);
}
私のコードの何が問題なのですか?i を 1 から 50 の間になるように修正しましたが、それでも超えていることに気付きました。