0

Basic code for input a series of strings. I trying to use it but this never ends and my solution is not getting printed. What possibly am I doing wrong ?

while (S.hasNext()) {
    String s = S.next();
    int max = 0;
    for (int i = 0; i < s.length(); i++) {
        if (Character.isUpperCase(s.charAt(i))) {
            max++;
        }
    }
    if (max > curr) {
        curr = max;
    }
}
System.out.println(curr);
enzo
  • 9,861
  • 3
  • 15
  • 38
Suyash25
  • 7
  • 2

1 Answers1

1

If you are using System.in as your input system, hasNext will always be true because the input stream is never closed. It just waits for more input. Similar question: Scanner.hasNextLine - always true

Spidy
  • 39,723
  • 15
  • 65
  • 83