why this program is not running? when compiled its says too many errors Can you
ID: 3666152 • Letter: W
Question
why this program is not running? when compiled its says too many errors
Can you redo this. thank you
import.java.until.Scanner;
public class Vowels {
private static Scanner sca;
public static void main(String arg[])
{
sca = new Scanner(System.in);
int a=0,e=0,i=0,o=0,u=0;
System.out.print("Enter String : ");
String str=sca.nextLine();
String str1=str.toLowerCase();
for(int j=0;j {
char c=str1.charAt(j);
switch(c)
{
case 'a':
a++;
break;
case 'e':
e++;
break;
case 'i':
i++;
break;
case 'o':
o++;
break;
case 'u':
u++;
break;
}
}
System.out.println("Vowel count in String "+str+" is : ");
System.out.println("a : "+a);
System.out.println("e : "+e);
System.out.println("i : "+i);
System.out.println("o : "+o);
System.out.println("u : "+u);
}
}
Explanation / Answer
Program:
import java.util.Scanner;
public class Vowels {
private static Scanner sca;
public static void main(String arg[])
{
sca = new Scanner(System.in);
int a=0,e=0,i=0,o=0,u=0;
System.out.print("Enter String : ");
String str=sca.nextLine();
String str1=str.toLowerCase();
for(int j=0;j<str1.length();j++)
{
char c=str1.charAt(j);
switch(c)
{
case 'a':
a++;
break;
case 'e':
e++;
break;
case 'i':
i++;
break;
case 'o':
o++;
break;
case 'u':
u++;
break;
}
}
System.out.println("Vowel count in String "+str+" is : ");
System.out.println("a : "+a);
System.out.println("e : "+e);
System.out.println("i : "+i);
System.out.println("o : "+o);
System.out.println("u : "+u);
}
}
Result:
Enter String : Once upon a time
Vowel count in String Once upon a time is :
a : 1
e : 2
i : 1
o : 2
u : 1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.