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

4 comments:

  1. Your site has a lot of useful information for myself. I visit regularly. Hope to have more quality items.

    ReplyDelete
  2. Looking forward to reading more.. Great post. Really Cool
    gmail login

    ReplyDelete
  3. in a multidimensional array (say a 2-dimensional array) containing many real numbers (both negative and positive), what do I need to do to be able to sort it in a certain dimension? (e.g. ascending or descending numeric values)
    thanks!

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...