import java.util.HashSet; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 String target= in.nextLine(); char[] ch =new char[target.length()]; for(int i=0; i<=target.length()-1 ; i++){ ch[i] = target.charAt(i); } char[] ch2=new char[target.length()]; int index=0; for(int i=target.length()-1 ;i>=0; i--){ ch2[index]=ch[i]; index=index+1; } String result =String.valueOf(ch2); System.out.println(result); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case String s = in.nextLine(); String reserved = reserve(s); System.out.println(reserved); } } private static String reserve(String text) { if (text == null || text.length() <= 1) { return text; } char[] chars = text.toCharArray(); StringBuilder builder = new StringBuilder(); for (int i = chars.length - 1; i >=0; i--) { builder.append(chars[i]); } return builder.toString(); } }
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.next(); String result = new StringBuilder(str).reverse().toString(); System.out.print(result); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 StringBuilder stringBuilder = new StringBuilder(in.nextLine()).reverse(); String ste = stringBuilder.toString(); System.out.print(ste); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // System.out.println("请输入要反转的字符串:"); String str = sc.nextLine(); System.out.println(new StringBuilder(str).reverse().toString()); } }
System.out.println(new StringBuilder(new Scanner( System.in).nextLine()).reverse());
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 StringBuilder sb = new StringBuilder(in.nextLine()); System.out.println(sb.reverse()); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s = sc.nextLine(); StringBuilder sb=new StringBuilder(s); System.out.println(sb.reverse().toString()); } }