Sunday, November 6, 2011

BlueJ Program On Circular Decoding Of A Word Or Sentence


Suppose the entered word is ‘Abz’, the output will be ‘bCA”. Each character in the word is increased by one character and if it exceeds the upper limit of letters, the starting character will be set. At the end of each character cases is to be changed. The upper case character will be changed to lower case and vice versa.

Here are the codes of the program.


import java.io.*;
class Smith
{
 String str;
 int i,len;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 public void take() throws Exception
 {
     System.out.println("Enter the word:");
     str=br.readLine();
     len=str.length();
     str=move();
     str=changeCase();
     System.out.println("Modified string="+str);
    }
    private String move()
    {
        char ch;
        String str1="";
       
        for(i=0;i< len;i++)
        {
             ch=str.charAt(i);
             if((ch>=65 && ch<=90)||(ch>=97 && ch<=122))
             ch=(char)(ch+1);
             if(ch==91)
             ch='A';
             if(ch==123)
             ch='a';
             str1=str1+ch;
            }
            return str1;
        }
        private String changeCase()
        {
           char ch;
        String str1="";
        for(i=0;i< en;i++)
        {
             ch=str.charAt(i);
             if(ch>=65 && ch< =90)
             ch=(char)(ch+32);
             else if(ch>=97 && ch< =122)
             ch=(char)(ch-32);
             str1=str1+ch;
            }
            return str1;
        }
        public static void main(String args[])throws Exception
        {
             Smith ob=new Smith();
             ob.take();
            }
        }
            
 Technical analysis of the circular decoding program

I have used three functions in this program. Function ‘public void take()’ takes the word from user and calls two other functions ‘private String move()’ and ‘private String changeCase()’. The first called function moves each letter by one and if the modified letter crosses the upper range, it is set back to starting letter and the second called function is used to change the case of each letters.

 Sample input and output of the circular decoding program

Enter the word:
Abc
Modified string=bCD

Enter the word:
AcX
Modified string=bDy

Related Post: BlueJ Programs on String/Sentence

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner