java - Getting 2 or more values then Checking them to be integer -


How can I get a user's 2 or more integer values ​​with the scanner class, then check them out; If they are all integers, then to run some statements and if only a warning is not shown that there is an accident!

I have written this code but with java it can not be right! Of course I know that from where there is a problem I only want something like this:

  scanner sc = new scanner (System.in); System.out.println ("Enter the first value:"); String v1 = sc.nextLine (); System.out.println ("Enter second value:"); String v2 = sc.nextLine (); If (v1.hasNextInt () and v2.hasNextInt ()) {}  

Change your code:

  scanner sc = new scanner (System.in); System.out.println ("Enter the first value:"); Int v1 = sc.nextInt (); // This line can be used before hasNextInt () System.out.println ("Enter second value:"); Int v2 = sc.nextInt (); // You can also use hasNextInt () before this line // You have 2 integer values.  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -