Monday 30 January 2017

Java Program To Delete All Vowels From A Sentence

Code:

import java.util.*;
public class Vowel
 {
    public static void main(String[] args)
   {
      char a[]=new char[80];
      String sent;
      Scanner s=new Scanner(System.in);
      System.out.print(" Write any Sentence : "); 
      sent=s.nextLine();  
      char[] b=sent.toCharArray();           /*toCharArray converts String value to Character Array*/
       int j=0; 
       for(int i=0;i<b.length;i++) 
       { 
             if(b[i]== 'A' || b[i]== 'E' || b[i]== 'I' || b[i]== 'O' || b[i]== 'U' ||  b[i]== 'a' || b[i]== 'e' || b[i]=='i' || b[i]== 'o' || b[i]== 'u') 
             {
                  continue;
             } 
             else 
             { 
                 a[j]=b[i]; 
                 j++;
             }
       }
       System.out.println();
       System.out.print("Result: ");
       System.out.println(a); 
   }
}

Output:



No comments:

Post a Comment