← All resources

Write a program to input a string and change the letters in upper case to lower case and vice versa.

import java.io.*;
public class Case_Convert
{
    public static void main()throws IOException
    {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String s, s2="";
         char ch;
         int i, l;
         System.out.println("Enter a string:");
         s = br.readLine();
         l = s.length();
         for(i=0;i<l;i++)
         {
             ch = s.charAt(i);
             if(ch>='A'&&ch<='Z')
             {
                 ch = (char)(ch+32);
             }
             else if(ch>='a'&&ch<='z')
             {
                 ch = (char)(ch-32);
             }
             s2 = s2+ch;
         }
         System.out.println("Output: "+s2);
    }
}