[java]代码库
方法1:
public class Main {
public static void main(String[] args) {
int [] a = new int[1000];
int j = 0;
for(int i = 100; i < 1000; i++)
{
int num1 = i / 100;
int num2 = i%100/10;
int num3 = i%100%10;
int numall = num1*num1*num1 + num2*num2*num2 + num3*num3*num3;
if(i == numall)
{
a[j] = i;
j++;
}
}
for(int k = 0; k < j; k++)
{
if(k == 0)
System.out.print(a[k]);
else
System.out.print("," + a[k]);
}
}
}
方法2:
import java.util.*;
public class Main{
public static void main(String[] args) {
int i, j = 0, a, b, c;
for(i = 100; i < 1000; i++) {
int data = i;
a = data%10;
data = data/10;
b = data%10;
data = data/10;
c = data;
if(i == a*a*a+b*b*b+c*c*c) {
if(j == 0)
System.out.print(i);
else
System.out.print("," +i);
j++;
}
}
}
}