Java计算水仙花数
2019-03-05 / JAVA / 913 次围观 / 0 次吐槽 /int count=0; for(int i = 100;i<=999;i++) { //取i的百位,十位,个位 int bw = i / 100; int sw = i % 100 /10; int gw = i % 10; //计算水仙花数 int num = bw*bw*bw+sw*sw*sw+gw*gw*gw; //判断水仙花数 if(i == num) { count++; System.out.println(i); } } System.out.println("总共有多少个:"+count+"数");
Powered By Cheug's Blog
Copyright Cheug Rights Reserved.