Bootstrap

习题:Java验证等式成立

今天的作业是:

要验证此等式成立,要用到循环语句和判断语句,以下是我的代码:

package quickstart;

public class Math1 {
    public static void main(String args[]) {
        int res = 0;
        for (int x = 3; x < 6; x = x + 1) {
            res = res + x * x * x;
            System.out.print(res);
            System.out.print("\n");
        }
        int res2 = 6 * 6 * 6;
        if (res == res2) {
            System.out.print("OK,第1个算式相等!");
        }
        res = 0;
        for (int x = 6; x < 70; x = x + 1) {
            res = res + x * x * x;
            System.out.print(res);
            System.out.print("\n");
        }
        res2 = 180 * 180 * 180;
        if (res == res2) {
            System.out.print("OK,第2个算式相等!");
        }
    }

}

  

转载于:https://www.cnblogs.com/huxiaoyi/p/10462327.html

;