You have been given a String S consisting of uppercase and lowercase English alphabets. You need to change the case of each alphabet in this String. That is, all the uppercase letters should be converted to lowercase and all the lowercase letters should be converted to uppercase. You need to then print the resultant String to output.
Input Format
The first and only line of input contains the String S
Output Format
Print the resultant String on a single line.
Constraints
where S denotes the length of string S.
Input Format
The first and only line of input contains the String S
Output Format
Print the resultant String on a single line.
Constraints
where S denotes the length of string S.
SAMPLE INPUT
abcdE
SAMPLE OUTPUT
ABCDe
Solution-
import java.util.Scanner;
class Tochangechar{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String str1=sc.nextLine();
StringBuffer str = new StringBuffer(str1);
int ln = str.length();
for (int i=0; i<ln; i++)
{
Character c = str.charAt(i);
if (Character.isLowerCase(c))
str.replace(i, i+1, Character.toUpperCase(c)+"");
else
str.replace(i, i+1, Character.toLowerCase(c)+"");
}
System.out.println(str);
}
}
Post a Comment