label: for (int i = 1; i <= 4; i++) { for (int j = 1; j <= 10; j++) { if (j % 4 == 0) { continue label; } System.out.print(j); } System.out.println(); }
答:123123123123
3.一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3。编程 找出1000以内的所有完数。(因子:除去这个数本身的其它约数)
答:
public class demo { public static void main(String[] args) { int factor = 0; for (int i = 1;i<=1000;i++){ for (int j = 1;j< i;j++){ if (i % j == 0){ factor += j; } } if (i == factor){ System.out.println(i); } //重置 factor = 0; } } }
****** ***** **** *** ** *
答:
public class demo { public static void main(String[] args) { for (int i = 0; i < 6; i++) { for (int j = 1; j < 6 - i; j++) { System.out.print("*"); } System.out.println(); } } }