判断一个正整数是否为质数Scanner sc=new Scanner(System.in); boolean isPrime = true; System.out.println("请输入一个大于等于2的正整数:"); int num = Integer.parseInt(sc.nextLine()); for ( ____; i < num; i++) { if (num % i == 0) { isPrime = ____; break; } } if (isPrime) System.out.println(num + "是质数!"); else System.out.println(num + "不是质数!");
查看答案
输出以下图形(第一行前没有空格)**************** ***** **** for(int i=1; ____;i++) { for(int j=1; ____;j++) { System.out.print(" "); } for(int j=1; ____; ____) { System.out.print("*"); } ____; }
打印下面平等四边形(第一行前4个空格,第二行前2个空格,最后一行没有空格)******* ************** for (int i = 1; ____; ____) { for (int j = 1; ____; j++) { System.out.print(" "); } for (int j = 1; ____; j++) { System.out.print("*"); } System.out.println(); }
打印200-300之间的所有素数 System.out.println("200-300之间的素数有:"); for (int num = 200; num <= 300; num++) { boolean isPrime = ____; for (int i = 2; i <= num - 1; i++) { if (num % i == 0) { isPrime = ____; break; } } if (isPrime) { System.out.print(num + " "); } }