InterviewSolution
Saved Bookmarks
| 1. |
Write a program in java to accept a string. Count all the letters in the string except the vowels |
|
Answer» import java.util.SCANNER; import java.io.*; public static void MAIN(String args[]) { Scanner SCAN = new Scanner(System.in); System.out.println("Enter the sentence"); String i = scan.nextLine(); int len=i.length(); int count = 0; for (char c: i.toCharArray()){ if(c == ' '||c == 'a' || c =='e' || c=='i' || c=='o' || c=='u' || c=='A'||c=='E' ||c=='I'||c=='O'||c=='U') count++; } int let=len-count; System.out.println("no of letters excluding vowels is "+let); }} |
|