键盘输入字符串 实现字符串反转

(第一种)public class StringFanZhuan {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入一个字符串");
        String zifu=sc.nextLine();
        System.out.println(zifu);
        StringBuffer i=new StringBuffer(zifu);
        i.reverse();
        System.out.println(i);
        sc.close();
    }
}

 

(第二种)

public class Test02_Reverse {

       public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);

             System.out.println("请输入一个字符串");

            String line = sc.nextLine();

            String reverse = new StringBuffer(line).reverse().toString();

             System.out.println(reverse);

}

}

posted @ 2019-01-23 16:34  隔壁小魏  阅读(719)  评论(0编辑  收藏  举报
求投食~(点图即可)