Week4: Solving the salesman problem, Working with strings Due: 2/12/2015 12:00:0
ID: 640223 • Letter: W
Question
Explanation / Answer
import java.util.Scanner;
//main class
public class VowelsDemo
{
public static void main(String[] args)
{
String str;
int count =0;
Scanner scn = new Scanner(System.in);
System.out.print("Enter a String: ");
str = scn.nextLine();
for(int i = 0; i < str.length(); i++)
{
if(str.charAt(i) == 'a' || str.charAt(i) == 'A')
{
count++;
}
else if(str.charAt(i) == 'e' || str.charAt(i) == 'E')
{
count++;
}
else if(str.charAt(i) == 'i' || str.charAt(i) == 'I')
{
count++;
}
else if(str.charAt(i) == 'o' || str.charAt(i) == 'O')
{
count++;
}
else if(str.charAt(i) == 'u' || str.charAt(i) == 'U')
{
count++;
}
}
System.out.println("Number of vowels: " + count);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.