How to read integer value from the standard input in Java?

You can use java.util. Scanner (API): import java.util. Scanner; //... Scanner in = new Scanner(System.In); int num = in.nextInt(); It can also tokenize input with regular expression, etc. The API has examples and there are many others in this site (e.g. How do I keep a scanner from throwing exceptions when the wrong type is entered?).

2 I second that solution. – Bozhidar Batsov Mar 24 '10 at 7:58.

If you are using Java 6, you can use the following oneliner to read an integer from console: int n = Integer. ParseInt(System.console().readLine()).

1 ...............:) – sgokhales May 18 at 9:46.

Check this one: public static void main(String args) { String input = null; int number = 0; try { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System. In)); input = bufferedReader.readLine(); number = Integer. ParseInt(input); } catch (NumberFormatException ex) { System.out.

Println("Not a number! "); } catch (IOException e) { e.printStackTrace(); } }.

– missingfaktor Mar 24 '10 at 8:13 Yeah, quite senseless! :-) I just changed it, thanks! – thelost Mar 24 '10 at 8:16.

Take a look at Teletype. Java from the Java Project Template. I believe it is exactly the utility you want.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions