I am supposed to create a program that counts the number of specific types of characters
entered by the user. The number of upper case letters, lower case letters, digits
(0 through 9) and other characters other than the # sign are counted. The user enters # to exit.
import java.util.Scanner;
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: ");
sym = input.next().charAt(0);
if (sym >= 'a' && sym <= 'z')
{
low++;
}
}
System.out.printf("Number of lowercase letters: %d\n", low);
}
}
That's what I have so far for the lowercase count. The problem is when I run the program and enter 4 lowercase letters, it only counts 3.
Home Worktag is OBSOLETE -> stackoverflow.com/tags/homework/info