私は現在、小学生のための数学ゲームを開発しています。私は、正しい質問を得るまで、ユーザーが継続的に回答を入力できるようにしています。その後、私は彼らに次の質問に移ります。下のコードを実行すると、正解を入力するチャンスは2回与えられますが、2回目以降は「正解」というメッセージが表示されません。正しい入力が入力されるまでスキャナが入力を要求し続けるようにする方法はありますか? Java
import java.util.Scanner;
public class test{
public static void main (String[]args){
Scanner kb= new Scanner(System.in);
double r5q1,r5q2,r5q3,r5q4,r5q5;
System.out.println("Welcome to the money level.. This is the last and most difficult level!");
//Question 1
System.out.println("Question 1: I have $10.00 and I buy a candy bar for $3.00. How much change will I get?");
r5q1=kb.nextDouble();
if(r5q1==7)
System.out.println("Correct!");
else
System.out.println("Try again!");
r5q1=kb.nextDouble();
}
}