Java基础----打印1到100之内的整数,但数字中包含9的要跳过

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lib_w/article/details/86573096

要求:
1.打印1到100之内的整数,但数字中包含9的要跳过
2.每行输出5个满足条件的数,之间用空格分隔
3.如:1 2 3 4 5

public class Test {
    public static void main(String[] args) {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            int ge = i % 10;
            int shi = i / 10 % 10;

            if (ge != 9 && shi != 9) {
                System.out.print(i + " ");
                count++;
                while (count % 5 == 0) {
                    System.out.println();
                    break;
                }
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/lib_w/article/details/86573096
今日推荐