2.22
2017
Day4 循环结构While语句的练习
class Test1_While { public static void main(String[] args) { //求1-100的和 int sxhh = 0; int i = 0; while (i <= 100) { sxhh = sxhh + i; i++; System.out.println(sxhh); } System.out.println(sxhh + "======================================="); //统计100-999内水仙花有多少 个 int ok = 0; int a =100; while (a<=999) { int ge = a % 10; int shi = a / 10 % 10; int bai = a /10 /10 % 10; if (ge*ge*ge+shi*shi*shi+bai*bai*bai == a) { ok++; System.out.println(ok); } a++; } System.out.println("水仙花一共有:" + ok ); } } |
上一篇
下一篇