One small...change....to the post made by bl00dninja ...
just one important thing....
try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
inData = br.readLine();
x = Integer.parseInt(inData);
}
catch (Exception e) {
System.err.println("Error");
/*you can use System.out.println
System.err.println is used sometimes
in catch block or may be most of time*/
}
You actually need to check wherther user inputs are appropriate. In java, it gives u a these try....catch blocks where u can catch an input error or any kind of error and display appropriate actions. However, in C++, u wud need to write 'if and else' kinda statements....
now what does try and catch do?
the try block is where all inputs are received...all your data entry work done in the try block...
whenever u make an error in input..the catch block wud immediately catch (hence the name!) and display the error message....
e.g..
say u ask the user to input a integer and the user enters a float, the try block indicates this value to the catch and the message stating the error is printed...
If more queries...feel free to ask....
there's a lot more to taking inputs in java....a very widely accepted and wide..wide..wide language....!!