This site requires JavaScript, please enable it in your browser!
Greenfoot back
LearningProgramming
LearningProgramming wrote ...

2013/4/30

Identifying non-Alphabetic Characters and Exception Handling in eclipse...

is there a way i can identify a non alphabetic characters like(., ? : ; ' " ! ) and numbers also
boolean checkChar = false;
		 for (int i=0;i<word.length();++i) {
		   if (Character.isLetterOrDigit(word.charAt(i))) {
		     checkChar=true;
		     break;
danpost danpost

2013/4/30

#
There are no built-in methods to do that; but, it would not be difficult to create your own methods to accomplish this task. For example:
private Boolean isDigit(char c)
{
    return "0123456789".indexOf(c) >= 0;
}
bourne bourne

2013/4/30

#
Can compare char values: return c >= '0' && c <= '9'; http://www.asciitable.com
Am trying to use it in an exception but i dont even know if my syntax if correct or not
You need to login to post a reply.