zoukankan      html  css  js  c++  java
  • for循环练习题1——水仙花数

    /*
    输出所有的水仙花数,
    所谓水仙花数是指一个3位数,
    其各个位上数 字立方和等于其本身。
    例如: 153 = 1*1*1 + 3*3*3 + 5*5*5

    */
    class ForTest3{

      public static void main(String[] args){
        int num1 = 0;//百位
        int num2 = 0;//十位
        int num3 = 0;//个位
        for(int i = 100; i < 1000; i++){
          num1 = i/100;//获取三位数中的百位数字
          num2 = i%100/10;//获取三位数中的十位数字
          num3 = i%100%10;//获取三位数中的个位数字
          //获取三次方
          double c1 = Math.pow(num1,3);
          double c2 = Math.pow(num2,3);
          double c3 = Math.pow(num3,3);
          //判断
          if((c1+c2+c3) == i){
          System.out.println(i);
          }
        }
      }
    }

  • 相关阅读:
    css 三角形
    转盘
    使用history.back()出现"警告: 网页已过期的解决办法"
    jQuery 左侧滑动
    Go语言数组的使用
    Go的变量作用域
    Go语言中函数的实现
    Go语言循环判断的使用~
    Go基础
    go环境的安装~
  • 原文地址:https://www.cnblogs.com/zhou-x/p/10833474.html
Copyright © 2011-2022 走看看