If i put a string into x
i want it to go back to the start of the code and let the "user" to input the INT again
but instead i get the exception "invalid input" wont stop
searched all over google cant find the answer
i want it to go back to the start of the code and let the "user" to input the INT again
but instead i get the exception "invalid input" wont stop
searched all over google cant find the answer
import java.util.Scanner;
public class temp {
static int x = 0 ;
static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
for (int i = 1 ; i < 2 ; i++){
try {
System.out.print("Enter your move X : ");
x = s.nextInt();
} catch (Exception e)
{System.out.println("invalid input try again ") ;
i--;} ;
}
System.out.println(x);
}
}