Topic describes
Describes taking a string containing only lowercase letters and then printing the string inverted. (The value contains a maximum of 1000 characters.)
Input description: Enter a string containing only lowercase letters.
Output description: Output the reversed character string.
Answer key
ACM mode, in fact, and the core mode is similar.
Stringbuilder direct method:
Run time: 30ms over 66.48% of code submitted in Java
Memory footprint: 10628KB over 31.40% of code submitted in Java
import java.util.Scanner; // Note that the class name must be Main, Public class Main {public static void Main (String[] args) {Scanner in = new Scanner(system.in); While (in.hasNextline ()) {while (in.hasNextline ()) {a = in.nextline (); String b = reverseString(a); // Call the core module system.out.println (b); } } public static String reverseString(String string) { if (string == null || string.length() == 0) return ""; StringBuilder sb = new StringBuilder(string); sb.reverse(); return sb.toString(); }}Copy the code