9.27 题目预测

9.27 题目预测


// 一个球 100米落下 求第十次落地共经过多少米
public static void Boom() {
    double heigh = 200;
    double sum = 0;
    for (int i = 1; i <= 10; i++) {
        sum += heigh;
        heigh /= 2;
    }
    System.out.println(sum - 100);

}

// 求a+aa+aaa+aaaa+a...a 的值
public static void continuePlus() {
    int n = 5;
    int a = 2;
    int n1 = n;
    int sum = 0;
    int temp = 0;
    while (n1 != 0) {
        temp = temp * 10 + a;
        n1--;
        sum += temp;
    }
    System.out.println(sum);

}

// 斐波那契数列数列的前20位 循环做
public static void fbnq() {
    int n = 20;
    int res = 1, pre = 1, temp = 0;
    for (int i = 1; i <= n; i++) {
        if (i == 1 || i == 2) {
            System.out.println(1);
        } else {
            temp = res;
            res = res + pre;
            pre = temp;
            System.out.println(res);
        }
    }
}

// 5块母鸡 3块公鸡 1块3只小鸡 100块100只
public static void chicken() {
    for (int m = 0; m <= 100 / 5; m++)
        for (int g = 0; g <= 100 / 3; g++)
            for (int x = 0; x <= 100; x++) {
                if (g + m + x == 100 && x % 3 == 0 && m * 5 + g * 3 + x / 3 == 100) {
                    System.out.println(m);
                    System.out.println(g);
                    System.out.println(x);
                }
            }
}

// 最大公约数
public static void gys() {
    int numin = 100;
    int numax = 13;
    int res = 1;
    for (int i = 2; i <= numin; i++) {
        if (numin % i == 0 && numax % i == 0) {
            res = i;
            break;
        }

    }
    System.out.println(res);
}

// 最小公倍数
public static void gbs() {
    int numin = 2;
    int numax = 5;
    for (int i = numin;; i++)
        if (i % numin == 0 && i % numax == 0) {
            System.out.println(i);
            break;
        }

}

// 输出质数
public static void zs() {
    int numin = 2;
    int numax = 100;

    for (int i = numin; i <= numax; i++) {
        boolean flag = true;
        for (int j = 2; j < i; j++) {
            if (i % j == 0) {
                flag = false;
                break;
            }
        }
        if (flag)
            System.out.println(i);
    }
}

// 输出水仙花数
public static void sxhs() {
    for (int i = 100; i < 1000; i++) {
        int a = i / 100;
        int b = i / 10 % 10;
        int c = i % 10;
        if (a * a * a + b * b * b + c * c * c == i) {
            System.out.println(i);
        }
    }

}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值