输入一个整数N,找出所有满足的组合;其中b <= c <= d
输出样例为Cube:a ,Triple(b,c,d)
import java.util.Scanner;
public class CubeTriple {
public static void main(String[] args) {
System.out.println("Input N");
Scanner in = new Scanner(System.in);
CubeTriple(in.nextInt());
}
public static void CubeTriple(int n){
if(n < 0){
System.out.println("ILLEGAL INPUT");
return;
}
for (int a = 0; a < n; a++)
for (int b = 0; b < a ; b++)
for (int c = b ; c < a;c++)
for(int d = c; d < a;d++)
if(a*a*a == b*b*b + c*c*c +d*d*d) System.out.println("Cube:"+a+" , Triple("+b+","+c+","+d+")");
}
}
输出结果: