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