展开全部
System.out.println("请输入要转换的字符串");
Scanner input = new Scanner(System.in);
String str = input.nextLine();
if(str.length() <= 20){
char[] chars = str.toCharArray();
StringBuffer buffer = new StringBuffer();
for(int i = 0 ;i < str.length(); i++) {
int a = chars[i];
if(a > 64 && a < 91){
chars[i] = (char)(a+32);
}
if(a >96 && a < 123) {
chars[i] = (char)(a-32);
}
buffer.append(chars[i]);
}
System.out.println(buffer.toString());
} else {
System.out.println("字符串长度不能超过20");
}
}
Scanner input = new Scanner(System.in);
String str = input.nextLine();
if(str.length() <= 20){
char[] chars = str.toCharArray();
StringBuffer buffer = new StringBuffer();
for(int i = 0 ;i < str.length(); i++) {
int a = chars[i];
if(a > 64 && a < 91){
chars[i] = (char)(a+32);
}
if(a >96 && a < 123) {
chars[i] = (char)(a-32);
}
buffer.append(chars[i]);
}
System.out.println(buffer.toString());
} else {
System.out.println("字符串长度不能超过20");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询