题解 | #数字颠倒#

数字颠倒

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

这个段代码跟优雅一点 但是没第一个易懂

这个 while判断到最后一个数字的时候就false 比如 3256014 数字的第1个“3” 3/10 = 0 。

假如给的数字是0 刚好代码 第17行 System.out.print(taget);

虽然看着代码简洁 但缺失为了这醋(简洁)包了饺子(代码不好看懂)。

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int taget = sc.nextInt();

       

        while (taget/10 != 0) {  
            int i = taget % 10;
            System.out.print(i);
            taget /= 10;
        }
        System.out.print(taget);


    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务