Code is copied!
Define a class to accept a string and print the same in reverse, also print the number of vowels in the string.
Eg :S =“BEAUTIFUL”
Output — “LUFITUAEB”
No. of vowels = 5
Eg :S =“BEAUTIFUL”
Output — “LUFITUAEB”
No. of vowels = 5
Solution:
import java.util.*;
class Reverse
{
public static void main (String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a word in upperCase");
String s = sc.nextLine();
s=s.toUpperCase();
String rev="";
int count=0;
for(int i=0; i< s.length(); i++)
{
char ch=s.charAt(i);
rev = ch + rev;
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
count++;
}
System.out.println(rev);
System.out.println("No. of vowels = " + count);
}
}