[Java] 纯文本查看 复制代码 import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String str = sc.nextLine();
char[] arr = new char[str.length()];
for (int i = 0; i < str.length(); i++) {
arr[i] = str.charAt(i);
}
for (int i = 0; i < arr.length; i++) {
if (arr[i] >= 'A' && arr[i] <= 'Z') {
arr[i] = (char) (arr[i] + 32);
}
}
if (arr[0] != arr[arr.length - 1]) {
char temp = arr[0];
arr[0] = arr[arr.length - 1];
arr[arr.length - 1] = temp;
}
for (int i = 0; i < arr.length; i += 2) {
arr[i] = '~';
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + ", ");
}
}
} |