0

I'm working on a while-loop which should check a text and see if letters are in CAPS or not as well as if they are vowels etc. I'm not sure of how to create a variable which can store certain letters. I asked this question yesterday an was told to use Array, but im wondering theres anyway to do this with help of Strings,charAt.

Bluebetty
  • 1
  • 3

2 Answers2

1

You can do this without a loop :-

String s = "HELLO";
if(s.toUpperCase().equals(s)){
    System.out.println("String is All-CAPS!");
}
dumbPotato21
  • 5,669
  • 5
  • 21
  • 34
0

Yes you can just iterate over the String with charAt() for every position. If you have a String text:

for(int i = 0; i < text.length() ; i++){
    char currentChar = text.charAt(i);
    doSomething(currentChar);
}
leurer
  • 441
  • 3
  • 10