Search This Blog

Wednesday, December 29, 2010

ICSE BOARD QUESTION 2008 - program to input a string and print out the text with the uppercase and lowercase letters reversed , but all other characters should remain the same as before.

/**ICSE BOARD QUESTION 2008
 * Write a program to input a string and print out the text
 * with the uppercase and lowercase letters reversed ,
 * but all other characters should remain the
 * same as before.
 * EXAMPLE: INPUT:  WelComE TO School
 *          OUTPUT: wELcOMe to sCHOOL
 *
 */
import java.io.*;
public class questionFIVE2008
{
    public static void main(String args[]) throws IOException
    {
        int ch;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("ENTER THE STRING ");
        String input=br.readLine();
        int len=input.length();
        int i;
        for(i=0; i<len; i++)
        {
            ch=input.charAt(i);
            if(ch>=65 && ch<=90)
            {
                ch=ch+32;
                System.out.print((char)ch);
            }
            else if(ch>=97 && ch<=122)
            {
                ch=ch-32;
                System.out.print((char)ch);
            }
            else
            {
                System.out.print((char)ch);
            }
        }
    }
}

OUTPUT:
ENTER THE STRING
WelComE TO School

wELcOMe to sCHOOL

8 comments: