This program is supposed to count the number of characters entered by a user. Where other is other characters such as !, @, $, etc. It is not supposed to count #. The following is my code to do this:
public class countchars {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
char sym;
int up = 0;
int low = 0;
int digit = 0;
int other = 0;
System.out.print("Enter a character # to quit: ");
sym = input.next().charAt(0);
while (sym != '#') {
System.out.print("Enter a character # to quit: ");
if (sym >= 'a' && sym <= 'z') {
low++;
}
if (sym >= 'A' && sym <= 'Z') {
up++;
}
if (sym >= '0' && sym <= '9') {
digit++;
}
if (sym >= '!' && sym <= '=') {
other++;
}
sym = input.next().charAt(0);
}
System.out.printf("Number of lowercase letters: %d\n", low);
System.out.printf("Number of uppercase letters: %d\n", up);
System.out.printf("Number of digits: %d\n", digit);
System.out.printf("Number of other characters: %d\n", other);
}
}
The problem is with the "other" counter. If I entered !, @, and $, it will only count 2 of the 3 characters entered. What's the wrong?