华为上机练习
博主的AC情况:
描述
将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。
输入描述:
输入一个字符串,可以有空格
输出描述:
输出逆序的字符串
示例1
输入:I am a student
输出:tneduts a ma I
解题代码:
import java.util.Scanner;
// 字符逆序(有空格)
public class HJ106 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
Reverse(str);
}
public static void Reverse(String x){
StringBuffer sb = new StringBuffer(x);
System.out.println(sb.reverse());
}
}