Hi,
I am beginner in java programming.
I want to create a program that will enable the user to input data?
I want to check if the input is numeric or not.
How to do it?
thanks!!!
lsvife -4 Junior Poster in Training
Recommended Answers
Jump to PostTry to parse the user input as a number; if it fails, the given string is not a valid number, otherwise it is. Look into the parseXXX method of the wrapper classes (Integer, Long, Float etc.).
Jump to PostThat's correct. Notice, however, that you're going to have to commit an act of minor barbarism, using a try/catch as a conditional. That is, you're going to put the parseInt in a try block, and if it returns an exception, you're going to take that as a "false". Since there …
All 5 Replies
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
jon.kiparsky 326 Posting Virtuoso
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
jon.kiparsky 326 Posting Virtuoso
mKorbel 274 Veteran 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.