21 lines
616 B
Java
21 lines
616 B
Java
package LanQiaoOJ;
|
||
/*
|
||
* 问题描述
|
||
153是一个非常特殊的数,它等于它的每位数字的立方和,即153=1*1*1+5*5*5+3*3*3。编程求所有满足这种条件的三位十进制数。
|
||
输出格式
|
||
按从小到大的顺序输出满足条件的三位十进制数,每个数占一行
|
||
*/
|
||
public class 特殊的数字 {
|
||
public static void main(String[] args) {
|
||
int a,b,c;//表示这个特殊的数的个位、十位、百位
|
||
for(int num=100;num<1000;num++) {
|
||
a=num%10;//对10求余,得到个位的值
|
||
b=num%100/10;//先对100求余,再对10取整,得到十位数上的值
|
||
c=num/100;//对100取整,得到百位数上的值
|
||
if(num==a*a*a+b*b*b+c*c*c) {
|
||
System.out.print(num+" ");
|
||
}
|
||
}
|
||
}
|
||
}
|