Checking for Alphabets in a String in java

后端 未结 6 1449
灰色年华
灰色年华 2021-01-16 21:46

I have a string \"BC+D*E-\". I want to check each character of the string whether it is an alphabet or not. I tried using isLetter() but it does consider even the = , * and

6条回答
  •  时光说笑
    2021-01-16 22:15

    This snippet may help you.

     String startingfrom = "BC+D*E-".toUpperCase();
            char chararray[] = startingfrom.toCharArray();
            for(int i = 0; i < chararray.length; i++) {
                                int value = (int)chararray[i];
                                if((value >= 65 && value <= 90) || (value >= 97 && value <= 122))
                                    System.out.println(chararray[i]+ " is an alphabate");
                                else 
                                    System.out.println(chararray[i]+ " is not an alphabate");
            }
    

提交回复
热议问题