编程题代码,仅供参考
第二讲 简单的Java程序
package week2; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub // int sum=0; // final int first = 3; // final int last = 5; // final int result = 6; // for(int x=first;x<=last;++x) // { // sum+=x*x*x; // } // if(sum==result*result*result) System.out.print("yes!"); // else System.out.print("No!"); // int sum=0; // final int first = 6; // final int last = 69; // final int result = 180; // for(int x=first;x<=last;++x) // { // sum+=x*x*x; // } // if(sum==result*result*result) System.out.print("yes!"); // else System.out.print("No!"); int sum = 0; int first = 1; final int last = 1000; for (int i = 1; i < last / 2; ++i) { first = i; sum = 0; for (int x = first; x <= last; ++x) { sum += x * x * x; for (int k = x + 1; k <= last; ++k) { if (sum == k * k * k) { System.out.printf("first=%d,...", first); System.out.printf("last=%d,", x); System.out.printf("result=%d\n", k); } } } } } }View Code