小编use*_*012的帖子

能被 1 到 20 中所有数字整除的最小正数?

我的代码有什么问题吗?当我运行该程序时,没有任何内容被打印。我想打印能被 1 到 20 的所有数字整除的最小数字。

found = False
i = 20
while found==False:
    c = 0    # c checks if the number is the one im looking for
    for x in range(1,21):
        if i%x==0:
            c = c + 1
    if c==20: # if c = 20 then its the number im looking for
        print i
        found = True
    i = i + 1    
Run Code Online (Sandbox Code Playgroud)

python

2
推荐指数
2
解决办法
2万
查看次数

特别毕达哥拉斯三胞胎

我的代码出了什么问题?当正确答案显然为6,8时,它打印2,2

public static void main(String[] args) {

    int a = 1;
    int b = 1;
    int answer = 0;
    int j = 4;
    while (j == 4) {
        for (a = 1; a <= 10; a++) {
            for (b = 1; b <= 10; b++) {
                answer = a * a + b * b;
                if (answer == 100) {
                    j = 10;
                }
            }
        }
    }
    System.out.println(a + " " + b);
}
Run Code Online (Sandbox Code Playgroud)

java pythagorean

0
推荐指数
1
解决办法
125
查看次数

标签 统计

java ×1

pythagorean ×1

python ×1