java 翁老师学习笔记-持续更

逆序输出一个整数

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

猜你喜欢

转载自www.cnblogs.com/allison-aichipingguo/p/11774212.html