面向对象—水仙花数

编写一个Java应用程序,该应用程序包括2个类:Print类和主类E类里有一个方法output()功能是输出100 ~ 999立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类Emain测试类Print 1 int f=0;//百位数赋值

 1  void output()
 2     {
 3         for(int j=100;j<=999;j++)//三位数的范围
 4         {
 5            int f=j/100;
 6             int g=j/10%10;
 7             int h=j%10;
 8             //例:153:153/100        百位数为1
 9                    //153/10%10   十位数是5
10                    //153%10           个位数是3
11             if(j==(f*f*f+g*g*g+h*h*h))
12             {
13                 System.out.println(j);
14             }
15            
16         }
17          
18     }
19     
20 
21     public static void main(String[] args) {
22         // TODO 自动生成的方法存根
23         Print print=new Print();
24         print.output();
25         
26     }

原文地址:https://www.cnblogs.com/yg6405816/p/5503739.html