Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Question About Numberic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question About Numberic" Watch "Question About Numberic" New topic
Author

Question About Numberic

Yanxin Zhao
Ranch Hand

Joined: May 05, 2004
Posts: 65
Hi: everyone
I want to konw that how to make sure a int number is numberic tpye? in other words, which method can return a boolean value if I input a numberic value ? I mean a method can judge whether a value is a numberic value or not.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
If you want to parse a String as an int value, then use the Integer.parseInt method. If it throws a NumberFormatException, then you know the String did not represent an int value.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
How about
boolean Character.isDigit( char ch )
??
API


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Yes, that's the best method if you are interested in testing a single char or testing the individual chars in a String.
Yanxin Zhao
Ranch Hand

Joined: May 05, 2004
Posts: 65
thank you all, my problem has been finished under your help. thinks so much.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Yanxin, what did you end up doing?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question About Numberic