import java.util.*; public class Main2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { String str = sc.nextLine(); StringBuilder sb = new StringBuilder(); for(int i = str.length()-1; i >= 0; i--) { char ch = str.charAt(i); sb.append(ch); } System.out.println(sb.toString()); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); while(scan.hasNext()) { String str = scan.nextLine(); Stack stack = new Stack(); for(char ch : str.toCharArray()) { stack.push(ch); } while(!stack.empty()) { System.out.print(stack.pop()); } } } }
import java.util.*; public class Main3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { String str = sc.nextLine(); StringBuilder sb = new StringBuilder(str); System.out.println(sb.reverse().toString()); } } }
题目描述
将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。 如:输入“I am a student”,输出“tneduts a ma I”。
输入参数:inputString:输入的字符串
返回值:输出转换好的逆序字符串
输入描述:输入一个字符串,可以有空格
输出描述:输出逆序的字符串
输入例子:I am a student
输出例子:tneduts a ma I