题解 | #数字颠倒#

数字颠倒

https://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int i1 = scanner.nextInt();
        if (i1 >= 0 && i1 <= Math.pow(2, 30) - 1) {
            String s = Integer.toString(i1);
            char[] chars = s.toCharArray();
            for (int i = chars.length; i > 0; i--) {
                System.out.print(chars[i - 1]);
            }
        } else {
            System.out.println("输入元素个数必须在0~(2的30次方-1)范围内");
        }


    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
ZywOo_求职版:谁问你了....
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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