注册 登录
编程论坛 JAVA论坛

求一个100以内的偶数输出并且每行输出5个,但我不知道我的错误在哪,求大佬指点

xi2254601605 发布于 2019-12-20 15:13, 5198 次点击
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
都是求一个100以内的偶数输出并且每行输出5个,但我不知道我的错误在哪,求大佬指点
12 回复
#2
xi22546016052019-12-20 15:14
为什么输出语句有错误
#3
xi22546016052019-12-20 15:21
只有本站会员才能查看附件,请 登录
#4
xi22546016052019-12-20 15:22
回复 3楼 xi2254601605
这样也不行
#5
纵横阳仔2019-12-20 16:19
偶数不应该是2,4,6,8,10.。。吗?
#6
纵横阳仔2019-12-20 16:22
continue会导致本次循环结束,后续代码不会执行的,编译就报错了
#7
LovelyFellas2019-12-25 06:11
偶数应该是判断能否被2整除,所以if语句后面应该是
if(j % 2 == 0)
    t++;

还有不要加continue,楼上解释是对的
#8
hulin1232020-03-17 18:11
。。。
#9
王小贱的书2020-04-17 09:27
//100以内的偶数,每行5个
public class BinO {
    public static void main(String[]argus) {        
        int a=0;//计数器
        for(int b=1;b<100;b++) {
            if(b%2==0) {
                System.out.print(""+b+" ");
                a++;
                if(a==5) {
                    System.out.println();
                    a=0;
                }
            }
        }
    }

}

运行结果:
2 4 6 8 10
12 14 16 18 20
22 24 26 28 30
32 34 36 38 40
42 44 46 48 50
52 54 56 58 60
62 64 66 68 70
72 74 76 78 80
82 84 86 88 90
92 94 96 98
这样可以吗?
#10
开车看海2020-05-05 00:03
public class forXunhuan {
    public static void main(String[] args) {

        for (int c = 1; c <= 100; c++) {
            if (c % 2 == 0) {
                System.out.print(c + " ");
            }
            if (c % 10 == 0) {
                System.out.print("\n");
            }
        }
    }
}
2 4 6 8 10
12 14 16 18 20
22 24 26 28 30
32 34 36 38 40
42 44 46 48 50
52 54 56 58 60
62 64 66 68 70
72 74 76 78 80
82 84 86 88 90
92 94 96 98 100
#11
撸代码的小杨2020-05-07 15:11
for (int i = 1; i <=100; i++)
        {
            if (i%2==0)
            {
                System.out.print(i+"\t");
            }
            if (i%10==0)
            {
                System.out.println();
            }
        }
#12
youou32020-05-17 10:55
public class PrintEven {
    public static void main(String[] args) {
        int t = 0;
        for (int i = 0; i <= 100; i++) {
            if(i%2==0){
                t++;
                System.out.print(i+"\t");
            }
            if (t%5==0){
                System.out.println();
            }
        }
    }
}
#13
sssooosss2020-05-31 10:04
学习了
1