plz tell the answer
Attachments:
Answers
Answered by
2
Question:-
Write a Java program to input a sentence and display the vowels.
Program:-
import java.util.*;
class Program
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the sentence: ");
String s=sc.nextLine();
System.out.print("Vowels are: ");
for(int i=0;i<s.length();i++)
{
char ch=s.charAt(i);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='E' || ch=='E' || ch=='E')
System.out.print(ch+" ");
}
}
}
This is simple. At First, take the input from the user and using charAt() method, get each character one by one and check if they are vowel. If it's true, then the vowels are printed.
Similar questions