输出100-999之间所有的水仙花数

来源:互联网 发布:数学不好能学编程吗 编辑:程序博客网 时间:2024/04/29 18:24

//7.输出100-999之间所有的水仙花数
public class P7 {

 public static void main(String[] args) {
  for(int x=100;x<=999;x++){
   int a=x/100;
   int b=x/10%10;
   int c=x%10;
   if(x==a*a*a+b*b*b+c*c*c){
    System.out.println(x);
   }
  }
  // TODO Auto-generated method stub

 }

}

0 0
原创粉丝点击