LanQiaoTestCodes/特殊的数字.java

21 lines
616 B
Java
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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+" ");
}
}
}
}