Sukonbu :
ループしながら、練習しながら、私はあなたがそれをロールバックするのにかかるどのように多くの試行乱数と、あなたの推測を入れ、コードを作ってみましたが、私はしばらくの内部で変数「チャンス」を宣言カントが、私はそれの前にそれを置けばそれだけで1つの番号を転がり続けます。
Random rng = new Random();
Scanner input = new Scanner(System.in);
System.out.println("Select a number you want to roll");
int choice = input.nextInt();
System.out.println("You feelin' lucky?\nHow many tries until you get " + choice);
int tries = input.nextInt();
int count = 0;
int chance = rng.nextInt((100)+1);
while (choice != chance) {
System.out.println(chance);
count++;
}
System.out.println("You won! It only took " + count + " tries.");
}
それはwhileループに入ったので、どのように私は、int型の機会を宣言することができますか?
コリンはルノー:
あなただけの再割り当てることができる機会をwhileループ内の新しい値に:
int count = 0;
int chance = rng.nextInt((100)+1);
while (choice != chance) {
System.out.println(chance);
chance = rng.nextInt((100)+1);
count++;
}