2024-10-22 08:19:19
一下代码仅供参考
public class Main {
public static void main(String[] args) {
String s = "aaBvdEFdsd";
StringBuffer ss = convertString(s);
System.out.println("大小写转换后是:" + convertString(s));
System.out.println("倒序输出后是:" + ss.reverse());
}
public static StringBuffer convertString(String str) {
String upStr = str.toUpperCase();
String lowStr = str.toLowerCase();
StringBuffer buf = new StringBuffer(str.length());
for (int i = 0, k = str.length(); i < k; i++) {
{
if (str.charAt(i) == upStr.charAt(i)) {
buf.append(lowStr.charAt(i));
} else {
buf.append(upStr.charAt(i));
}
}
}
return buf;
}
}
2024-10-22 17:20:37
public static void main(String[] args) {
System.out.print("请选择输出的模式【1小写;2大写】:");
Scanner in=new Scanner(System.in);
int choose=in.nextInt();
System.out.print("请输入字符串:");
Scanner inn=new Scanner(System.in);
String str=inn.nextLine();
StringBuffer sb=new StringBuffer(str);
if(choose==1){
System.out.println(sb.reverse().toString().toLowerCase());
}else{
System.out.println(sb.reverse().toString().toUpperCase());
}
}
2024-10-22 17:58:40