Sunday, September 11, 2011

BlueJ Program To Change All The Vowels In A Sentence With The Next Vowel


In this program, user will enter a sentence and all the vowels, if present in the sentence will be converted into the next vowel. For example ‘I’ will be converted into ‘O’ and ‘i’ will be ‘e’. Similar effects will be on every vowels present in the sentence.

 Codes of the program

import java.io.*;
class Vowel
{
String name;
char arr[]={ 'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'};
int i,len, alen,j;
char ch;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 public void take()throws Exception
 {

  System.out.println("Enter the sentence:");
  name=br.readLine();
 len=name.length();
 alen=arr.length;
 for(i=0;i< len;i++)
 {
     ch=name.charAt(i);
      switch(ch)
      {
          case 'a':
          case 'A':
          case 'e':
          case 'E':
          case 'i':
          case 'I':
          case 'o':
          case 'O':
          case 'u':
          case 'U':
          for(j=0;j< alen;j++)
          if(ch==arr[j])
          break;
          if(j< alen-2)
          System.out.print(arr[j+2]);
          else
          {
              j=j-(alen-2);
          System.out.print(arr[j]);
          }
          break;
          default:
          System.out.print(ch);
        }
    }
}
       
  public static void main(String args[]) throws Exception
  {
   Vowel ob=new Vowel();
  ob.take();
   }
   }

 In this program all the vowels, including upper case and lower case are stored in a char type array in sequence. Each character of the entered sentence is accessed and checked whether it is vowel or not. When any vowel is found, the next vowel is accessed from the array and displayed. In case of non vowel character, the character is displayed.
Care has been taken to check if the vowel appears in the last pair of the array, in such case the vowel character from the beginning pair is to be displayed.
  
Sample Input: This is a vOwel Test
Sample output: Thos os e vUwel Tist

Sample Input:This IUu of teuo
Sample output: Thos OAa uf tiau


Related Post: BlueJ Programs on String/Sentence


2 comments:

  1. sir can you please give me the practical programs for isc from the year 2000 to 2009.At least the links.please

    ReplyDelete
  2. In this site you will get ISC practical papers of several years. Search it.

    ReplyDelete

Subscribe via email

Enter your email address:

Delivered by FeedBurner