Answer to Question #294716 in Java | JSP | JSF for Mesul

Question #294716

Write a program to take a String as input then display the words which starts with vowel and also display how many such words found.

For example:

Enter a String

HELLO world elePhaNt rUsh imagine

Words which start from vowel

elePhaNt imagine

No. of such words: 2


1
Expert's answer
2022-02-07T12:50:43-0500
import java.util.*;


class App {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.println("Enter a String: ");
		String inputWords[] = in.nextLine().split(" ");
		int n = 0;
		System.out.println("Words which start from vowel");
		for (String word : inputWords) {
			if (word.toLowerCase().charAt(0) == 'a' || word.toLowerCase().charAt(0) == 'e'
					|| word.toLowerCase().charAt(0) == 'i' || word.toLowerCase().charAt(0) == 'o'
					|| word.toLowerCase().charAt(0) == 'u') {
				System.out.print(word + " ");
				n++;
			}
		}
		System.out.println("\nNo. of such words: " + n);


		in.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS