打印所有的水仙花说,水仙花说指一个三位数,其各位数字的立方和等于该数本身.
例如153=1的三次方+5的三次方+3的三次方.
/** * Created by chenlongbo on 2017/6/3. */public class Roem { public static void main(String[] args) { int a, b, c; for (int i = 100; i <= 999; i++) { //百位数 a = i/100; //十位数 b = (i % 100)/10; //个位数 c = i % 10; if( i == a*a*a + b*b*b + c*c*c){ System.out.println(i); } } } 控制台:
153
370371407Process finished with exit code 0