【API】反转输入字符(Java)

2019-08-08 00:00:00 输入 字符 反转

请求输入字符,

输出反转。

 

 1 import java.util.Scanner;
 2 
 3 public class T01 {
 4 
 5     public static void main(String[] args) {
 6         /**
 7          * get str from kbd
 8          * out a new str that sakasamad
 9          */
10         System.out.print("in put a str :  | ");
11         String str = new Scanner(System.in).nextLine();
12         str = new StringBuilder(str).reverse().toString();
13         System.out.print("FanZhuan :      | "+str);
14         
15         System.out.println("\n- -------------- --- -\n");
16         
17         System.out.print("in put a str :  | ");
18         System.out.print("FanZhuan :      | "+new StringBuilder(new Scanner(System.in).nextLine()).reverse().toString());
19     
20     
21         //well... i don't know how to use close() now...    
22     }
23 }

 

试了试行数更少的写法,还真也行,输出效果没有坏掉。

 

—-

 

话说玩API比搞项目舒服多了……

相关文章