SPPU
TY BBA(Computer Applications) 2019 CBCS Pattern
Question
Write a java program to display all the vowels from a given string.
Solution:
Hey, folks, today I will help you in solving core java slips of T.Y.B.C.A. InT.Y.B.C.A. In this program, you’ll learn to display all the vowels from a given string.
Code:
import java.lang.*;
import java.util.*;
class Vowels extends Thread
{
String s1;
Vowels(String s)
{ s1=s;
start();
}
public void run()
{
System.out.println("Vowels are ");
for(int i=0;i<s1.length();i++)
{
char ch=s1.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
System.out.print(" "+ch);
}
}
}
public class Vowelsfind {
public static void main(String[] args)
{
Scanner sn=new Scanner(System.in);
System.out.println("Enter a string");
String str1=sn.next();
Vowels v=new Vowels(str1);
}
}
Step 1
Save the file as Vowelsfind.java
Step 2
Open the Command promote and execute the follwing code
javac Vowelsfind.java
Step 3
after completing the last step execute this command
java Vowelsfind
Result
Enter a string
aeiouadadafsseiou
Vowels are
a e i o u a a a e i o u