import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); //创建键盘录入对象
System.out.println("请输入一个字符串:");
String line = sc.nextLine(); //接收字符串
char[] arr = line.toCharArray(); //字符串转数组
//遍历并换位置
for (int sta = 0,end = arr.length - 1; sta < end; sta++,end--) {
char temp = arr[sta];
if (arr[sta] != arr[end]) {
arr[sta] = arr[end];
arr[end] = temp ;
}
}
//加*号
StringBuffer sb = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
if (i == arr.length - 1) {
sb.append(arr[i]);
}else {
sb.append(arr[i]).append("*");
}
}
System.out.println("处理后:");
System.out.println(sb);
}
} |