Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Question how to get back to start of code

$
0
0
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
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);





}

}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>