Java program to accept a String and Convert the case of each alphabet present in it.(eq- JaVa---jAvA)
import java.util.Scanner;
public class demo{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
@SuppressWarnings("unused")
String str = sc.nextLine();
sc.close();
@SuppressWarnings("unused")
String temp ="";
char ch;
for(int i=0;i<str.length();i++){
if(Character.isAlphabetic(str.charAt(i))) {
if(Character.isUpperCase(str.charAt(i)))
ch = Character.toLowerCase(str.charAt(i));
else
ch = Character.toUpperCase(str.charAt(i));
temp = temp + ch;
continue;
}
temp = temp + str.charAt(i);
}
System.out.println(str);
System.out.print(temp);
}
}
Comments
Post a Comment