/*1:请编写程序,将键盘录入的字符串倒序打印,并测试。
例: 键盘输入:abcde
打印输出:edcba*/
public class daoxu {
public static void main(String[] args) {
System.out.println("请输入字符串,将倒序打印");
Scanner sc = new Scanner(System.in);
String s = sc.next();
//方法一
for (int i=s.length()-1;i>=0;i--){
char n= s.charAt(i);
System.out.print(n);
}
System.out.println();
//方法二
StringBuffer s1 = new StringBuffer();
s1.append(s);
StringBuffer s2 = s1.reverse();
System.out.println(s2);
}
}
|
|