Sunday, January 12, 2014

BlueJ Program On Changing Case Of Letters



In this BlueJ program, user will enter a sentence and the sentence will be displayed after converting every alternate character to uppercase and immediate next character in lowercase                                                                                                                    


import java.io.*;
class CaseChange
{
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 String s1,s2="";
 char ch;
 int i,len,x=0;
  public void takeName() throws Exception
 {
  System.out.println("Enter Name:");
  s1=br.readLine();
  System.out.println("Original Name="+s1);
  len=s1.length();
  for(i=0;i< len;i++)
  {
  ch=s1.charAt(i);
  if(x%2==0 && Character.isLetter(ch))
  ch=Character.toUpperCase(ch);
else  if(x%2==1 && Character.isLetter(ch))
  ch=Character.toLowerCase(ch);
  x++;
s2=s2+ch;
}
 System.out.println("Modified Name="+s2);
    }
    public static void main(String args[]) throws Exception
    {
    CaseChange ob=new CaseChange ();
    ob.takeName();
    }
    }

Sample input and output of the program


Input:  Nasim Akhtar

Output:    NaSiM aKhTeR     

Related Post: BlueJ Programs on String/Sentence                      

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner