Write a program that reads in characters from the keyboard until it reads a line feed character '\n'. Then have it print the number of vowels, the number of consonants, the number of digits, and the number of other characters. Include the final line feed character in your count of other characters.
I did the most of them but when I type in \n, it dosen't stop. Can anyone give me some help?
import java.util.Scanner;
class characters{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int v=0;
int c=0;
int n=0;
int o=0;
char ch;
do{
System.out.println("Type in any characters: ");
System.out.println("Type in \\n to stop. ");
ch = scan.next().charAt(0);
if(ch=='\n') {
o++;
break;}
else
{
if('a'<=ch && ch<='z')
{
if(ch=='a') v++;
else if(ch=='e') v++;
else if(ch=='i') v++;
else if(ch=='o') v++;
else if(ch=='u') v++;
else c++;
}
else if('0'<=ch && ch<='9') n++;
else o++;
}
}while(ch!='\n');
System.out.println("There are "+v+" vowels, "+c+" consonants, "+n+" digits, and "+o+" other characters.");
}
}