标签:ring img col 控制 ESS 水仙花 ber com color
执行流程图:
public static void main(String[] args) { int count = 0; for (int i = 100; i < 1000; i++) { int ge = i % 10; int shi = i / 10 % 10; int bai = i / 10 / 10 % 10; int result = ge * ge * ge + shi * shi * shi + bai * bai * bai; if (result == i) { System.out.println(result+"是水仙花数"); } } }
public static void main(String[] args) { int count = 0; for (int i = 100; i < 1000; i++) { int ge = i % 10; int shi = i / 10 % 10; int bai = i / 10 / 10 % 10; int result = ge * ge * ge + shi * shi * shi + bai * bai * bai; if (result == i) { count++; } } System.out.println("水仙花共有:" + count + "个"); }
执行流程图:
public static void main(String[] args) { int count = 0; int zf = 8844430; double paper = 0.1; while(paper <= zf) { count++; paper *= 2; } System.out.println(count); }
执行流程图:
死循环会有一直输出,除非手动停止。
代码实例:
改进:
继续改进:
结果都为:
public static void main(String[] args) { Random r = new Random(); int number = r.nextInt(100)+1; System.out.println("随机数是"+number); while (true){ Scanner sc = new Scanner(System.in); System.out.println("请输入你要猜的数字"); int guessNumber = sc.nextInt(); if(guessNumber > number){ System.out.println("你猜的数字大了"); }else if(guessNumber < number){ System.out.println("你猜的数字小了"); }else{ System.out.println("猜中了"); break; } } }
标签:ring img col 控制 ESS 水仙花 ber com color
原文地址:https://www.cnblogs.com/ajing2018/p/14635122.html