im beginner in java programing, have task need to be completed and looking for some useful tips. writing program which requires from user correct Float input, if input is incorrect, program gives another chance until correct input, my problem is next, when i enter incorrect input it runs non stop,, any ideas?
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
float f = 0;
int x = 1;
do {
try {
System.out.print("Enter an float:");
f = in.nextFloat();
x =2;
} catch (InputMismatchException e) {
System.err.println("Incorrect entry.");
}
System.out.println("Your entry is:" + f);
}
while(x==1);
}