逆序输出一个整数

int a = in.nextInt();
        int count = 0;
        do {
            count = count *10 +a %10;
            a /=10;
        }while (a>0);
        System.out.println(count);
View Code

 

                int a = in.nextInt();
        int count = 0;
        do {
            System.out.print(a%10);
            a/=10;
        }while (a>0);
View Code

 正序输出一个已知位数的整数

//已知:
        //n 是x的位数
        int n =4;
        // mode:10的n-1次方
        int mode = 1000;
        int x = in.nextInt();
        for(int i=0;i<n;i++) {
            System.out.println(x/mode);
            x%=mode;
            mode /=10;
        }
View Code

 

posted on 2019-10-31 22:14  空谈误国-实干兴邦  阅读(173)  评论(0编辑  收藏  举报