常规方法:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner inScanner = new Scanner(System.in); String string = inScanner.next(); char[] ch = string.toCharArray(); int a = string.length()-1; for (int i = 0; i < ch.length; i++) { ch[i]=string.charAt(a); a--; } String string2 = new String(ch); String string3 = string.concat(string2); System.out.println(string3); } }
简单方法:利用reverse()
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner inScanner = new Scanner(System.in); String string = inScanner.next(); StringBuffer sBuffer = new StringBuffer(); System.out.println(string+sBuffer.append(string).reverse()); } }
0.0分
4 人评分