以纯字符串方法处理数字的逆序字符串

数字颠倒

http://www.nowcoder.com/questionTerminal/ae809795fca34687a48b172186e3dafe

题目描述
描述:

输入一个整数,将这个整数以字符串的形式逆序输出

程序不考虑负数的情况,若数字含有0,则逆序形式也含有0,如输入为100,则输出为001

使用纯字符串的解法:

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int num = sc.nextInt();
            String s = String.valueOf(num);
            StringBuilder sb = new StringBuilder();
            for(int i=s.length()-1; i>=0; i--){
                sb.append(s.charAt(i));
            }
            System.out.println(sb.toString());
        }
    }
}




全部评论
正解
点赞 回复 分享
发布于 2021-07-09 20:08

相关推荐

点赞 评论 收藏
分享
09-29 15:34
已编辑
北京航空航天大学 C++
做个有文化的流氓:结果是好的,过程不重要,而且你的offer太多了
软开人,秋招你打算投哪些...
点赞 评论 收藏
分享
评论
4
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务