In Java, if you want to ask users, for example, to input numbers only between 1,000 and 100,000, the program would continue further. Otherwise, ask the user to input the number again in the given range.
Edit: Here, my program only tries to validate the input only once. How shall I make to ask the user to input until valid data(i.e between 1000-100000) is entered
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Principal:");
double principal = sc.nextDouble();
if(principal<1000 || principal >100000) {
System.out.println("enter principal again:");
principal = sc.nextDouble();
}
}