标签:oid 多少 结束 循环 main while 练习 mamicode inf
初始化语句;
while(判断条件语句) {
循环体语句;
控制条件语句;
}
1.求1-100之和:
class Hello2 { public static void main(String[] args) { int sum = 0; int i = 1; while (i <= 10) { sum += i; i++; } System.out.println(sum); } }
结果:
2.统计”水仙花数”共有多少个:
class Hello2 { public static void main(String[] args) { int count = 0; int i = 100; while (i <= 999) { int ge = i % 10; int shi = i / 10 % 10; int bai = i / 100 % 10; if (i == ge * ge * ge + shi * shi * shi + bai * bai * bai) { count++; } i++; } System.out.println(count); } }
结果:
标签:oid 多少 结束 循环 main while 练习 mamicode inf
原文地址:https://www.cnblogs.com/Wangzui1127/p/11167098.html