public class Main {
public static void main(String[] args){
String str1 = new String("MoHuNeKo");
String upper_str1 = str1.toUpperCase();
String lower_str1 = str1.toLowerCase();
System.out.println("Input string: " + str1);
System.out.println("The first letter is uppercase? : " + Character.isUpperCase(str1.charAt(0)));
System.out.println("Uppercase conversion: " + upper_str1);
System.out.println("Lowercase conversion: " + lower_str1);
System.out.println("=======^・ Ω ・^=======");
String str2 = new String("The current world population is about 7,594,690,000!");
String upper_str2 = str2.toUpperCase();
String lower_str2 = str2.toLowerCase();
System.out.println("Input string: " + str2);
System.out.println("The second letter is lowercase? : " + Character.isLowerCase(str2.charAt(1)));
System.out.println("Uppercase conversion: " + upper_str2);
System.out.println("Lowercase conversion: " + lower_str2);
System.out.println("==============");
System.out.println("uppercase letter? : " + Character.isUpperCase('\n'));
System.out.println("Lowercase? : " +Character.isLowerCase('\t'));
}
}
Input string: MoHuNeKo
The first letter is uppercase? : true
Uppercase conversion: MOHUNEKO
Lowercase conversion: mohuneko
=======^・ Ω ・^=======
Input string: The current world population is about 7,594,690,000!
The second letter is lowercase? : true
Uppercase conversion: THE CURRENT WORLD POPULATION IS ABOUT 7,594,690,000!
Lowercase conversion: the current world population is about 7,594,690,000!
==============
uppercase letter? : false
Lowercase? : false
Create a program that swaps lowercase and uppercase letters in a given string. Input The string is given on one line. Output Please output the character string in which the lowercase letters and uppercase letters of the given character string are exchanged. Please output the characters other than the alphabet as they are. Constraints
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
StringBuilder sb = new StringBuilder();
for(int i = 0; i < line.length() ; i++){
char now = line.charAt(i);
if(Character.isUpperCase(now)) sb.append(Character.toLowerCase(now));
else if(Character.isLowerCase(now)) sb.append(Character.toUpperCase(now));
else sb.append(now);
}
System.out.println(sb);
}
}
Recommended Posts