SWAP CASE OF A STIRNG.
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);
}
}
0 Comments