封装类-水仙花

 1 package com.hanqi.z1p1;
 2 
 3 public class Print {
 4 
 5     
 6     void output()
 7     {
 8         for(int x=1;x<=9;x++)
 9         {
10             
11             for(int y=0;y<=9;y++)
12             {
13                 
14                 for(int z=0;z<=9;z++)
15                 {
16                     int sum=x*x*x+y*y*y+z*z*z;
17                     if(sum==x*100+y*10+z)
18                     {
19                         System.out.println(sum);
20                     }
21                 }
22             }                                    
23         }
24         
25     }
26         
27     
28     public static void main(String[] args) {
29         // TODO 自动生成的方法存根
30 
31         
32         Print op=new Print();
33         op.output();
34         
35     }
36 
37 }

运行结果:

原文地址:https://www.cnblogs.com/miss123/p/5501390.html