Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question About Numberic  RSS feed

 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marilyn de Queiroz
Sheriff
Posts: 9081
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about
boolean Character.isDigit( char ch )
??
API
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all, my problem has been finished under your help. thinks so much.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yanxin, what did you end up doing?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!