Reverse of a String and Number of Vowels - Java Program - Scanner


Reverse of a String and Number of Vowels  
 Scanner -Java Program
Program: Reverse.java
import java.util.Scanner;
class Reverse 
{
public static void main(String args[])
{
 String string,reverseString = "";
 int vowelCount=0;
 
   Scanner sc=new Scanner(System.in);
   System.out.print("Enter the word: ");
   string= sc.nextLine();
   
   for(int i=string.length()-1;i>=0;i--)
   {
    char ch=string.charAt(i);
    reverseString+=ch;
    if(ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=='O'||ch=='o'||ch=='U'||ch=='u')
    vowelCount++;
   }
   
   
   System.out.println("Reverse: "+reverseString+"\nNumber of vowels: "+vowelCount);
   
}
}

Output:
Enter the word: 2k8cse
Reverse: esc8k2
Number of vowels: 1

2 comments:

Related Posts Plugin for WordPress, Blogger...