Write a program to accept a word and pass this word to a function name void display(String str). Display all the vowels present in the word in java.
Write a program to accept a word and pass this word to a function name void display(String str). Display all the vowels present in the word in java.
public class ReturnVowel
{
static void display(String str){
String s = str.toLowerCase();
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='a'||s.charAt(i)=='e'||s.charAt(i)=='i'||s.charAt(i)=='o'||s.charAt(i)=='u'){
System.out.println(str.charAt(i));
}
}
}
public static void main(String args[]){
String name = "cOmputer";
display(name);
}
}
Output
O
u
e
Comments
Post a Comment