Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Lloyd Alvarez   on May 18 In Java Category.

  
Question Answered By: Leon Evans   on May 18

Try this,
------------------------------------------------------------
.......... you code..........
try {

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

String userText = in.readLine(); // return  String from System's default input
stream

// Converting user input  from String to int

int userValue = 0; // to be safe from null value
userValue = Integer.parseInt( userText ); // this will throw
NumberFormatException if user  have entered  something except integer value

// This section will only print if user input was interger
System.out.println(" You entered: " + userValue );

}
catch(NumberFormatException numException) {
System.out.println("Sorry you have not enter an integer, Exception is: " +
numException);
}

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Simple solution to input? Or get search suggestion and latest updates.


Tagged: