import java.util.Scanner;
public class Vowel
{
public static void main(String[] args)
{
int c=0,v=0;
String s;
Scanner in =new Scanner(System.in);
System.out.println("Enter String :");
s = in.nextLine();
s = s.toLowerCase();
for(int i = 0 ;i<s.length();i++)
{
char ch = s.charAt(i);
if (ch == 'a' || ch == 'e' || ch == 'i' ||
ch == 'o' || ch == 'u'){
v++;
}
else if(ch == ' '){
}
else if (Character.isDigit(s.charAt(i)))
{
}
else
c++;
}
System.out.println("Vowels are "+v+" and consonants are "+c);
}
}
output:
Enter string:
Hello World
Vowels are 3 and consonants are 7.
public class Vowel
{
public static void main(String[] args)
{
int c=0,v=0;
String s;
Scanner in =new Scanner(System.in);
System.out.println("Enter String :");
s = in.nextLine();
s = s.toLowerCase();
for(int i = 0 ;i<s.length();i++)
{
char ch = s.charAt(i);
if (ch == 'a' || ch == 'e' || ch == 'i' ||
ch == 'o' || ch == 'u'){
v++;
}
else if(ch == ' '){
}
else if (Character.isDigit(s.charAt(i)))
{
}
else
c++;
}
System.out.println("Vowels are "+v+" and consonants are "+c);
}
}
output:
Enter string:
Hello World
Vowels are 3 and consonants are 7.
this program counts vowels and consonants only .. where is the "quit" logic ??
ReplyDelete