首页 > 编程语言 > 详细

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

时间:2019-06-09 23:50:56      阅读:183      评论:0      收藏:0      [点我收藏+]

请求输入字符,

输出反转。

 

 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比搞项目舒服多了……

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

原文:https://www.cnblogs.com/senwren/p/str_sakasama_Java.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!