Can someone help me with error trapping. For instance, if I asked the user to input only a numeric type, 0-9. Then how would I go about creating an error message if the user inputs "hey." I know that I could easily use the Try, Catch statements but I want to learn the other ways.
BuhRock
0
Light Poster
Recommended Answers
Jump to Post// get input up here into char variable 'userInput' if (Character.isDigit(userInput)){ //do something } else System.out.println("That wasn't 0-9...");
Jump to Post"input" as defined in your code is a String. The Character.isDigit() method takes a char as an argument, as my comment above the code I gave you earlier suggests.. not a String. Furthermore even if you did manage to read in the first character of what the user entered using …
All 6 Replies
BestJewSinceJC
700
Posting Maven
BuhRock
0
Light Poster
BestJewSinceJC
700
Posting Maven
chaospie
0
Newbie Poster
BuhRock
0
Light Poster
chaospie
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.