Advertisements
Advertisements
प्रश्न
Define a class to accept a string and convert it into uppercase. Count and display the number of vowels in it.
| Input: | robotics |
| Output: | ROBOTICS |
| Number of vowels: | 3 |
कोड लेखन
Advertisements
उत्तर
import java.util.Scanner;
class VowelCount
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a word");
String str=sc.next().toUpperCase();//string converted to upper case
int len=str.length();
int count=0;
for(int i=0;i<len;i++)
{
char c=str.charAt(i);//extracting each character from the string
if(c=='A'||c=='E'||c=='T' ||c=='O'||c=='U')
count++;
}
System.out.println(str+"\nNumber of vowels: "+count);
}
}shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 10: String Handling - Exercises [पृष्ठ २४९]
