Write a program in java to accept a word /string . Counting all the letters excluding the vowels present in the word / string and display the result
Answers
Answered by
22
import java.util.*;
class str
{
public static void main(String args[])
{
int count =0;
Scanner sc = new Scanner (System .in);
System.out.println("Enter a string:");
String str = sc nextLine();
int len = str . length();
for(int i=0; i<len; i++)
{
char ch = str . charAt(i);
if(ch=='A'||ch=='a'|| ch=='E' || ch=='e' || ch=='I'|| ch=='i'|| ch=='O'|| ch=='o'|| ch=='U'|| ch=='u')
{
continue ;
}
else
{
count++;
}
}
System.out.println("The total no. of letters present in"+ str + "are="+ count);
}
}
Enter a string : Good
The total no of letters present in Good are = 2
__________________________________
Attachments:
Similar questions