Java program to convert uppercase string to lowercase and vice versa.

SWAP CASE OF A STIRNG.






                                                          This is a simple java program that will swap CASE of string ; It means if entered string is in LOWERCASE then our program will convert whole string in UPPERCASE and Vice versa. 


JAVA CODE : ) 



import java.util.Scanner;


public class UpperandLower


{


public static void main(String[] args)


{


   String str,s=" ";


   Scanner ip=new Scanner(System.in);


   System.out.println("Enter UpperCase String:");


   str=ip.nextLine();


   for(int i=0;i<str.length();i++)


   {


      if(str.charAt(i)>='A' && str.charAt(i)<='Z')


     {


     s=s+(char)(str.charAt(i)+32);


     }


    else


     {


       s=s+str.charAt(i);


     }


   }


   System.out.print(s);


   String str1,s1=" ";


   System.out.println("\nEnter Lowercase string:");


   str1=ip.nextLine();


   ip.close();


   for(int j=0;j<str1.length();j++)


   {


     if(str1.charAt(j)>='a' && str1.charAt(j)<='z')


     {


       s1=s1+(char)(str1.charAt(j)-32);


     }


     else


     {


       s1=s1+str1.charAt(j);


     }


   }


   System.out.print(s1);


}


}



INPUT && OUTPUT :-  



Post a Comment

0 Comments