import java.util.Scanner;
public class Count {
public static void main(String[] args){
int a = 0;
int b = 0;
int c = 0;
Scanner input = new Scanner(System.in);
for(int i = 0; i<10; i++){
int num = input.nextInt();
if(num == 0)
a++;
else if(num > 0)
b++;
else
c++;
}
input.close();
System.out.println("正数个数为"+b+"负数个数为"+c+"0的个数为"+a);
}
}
您会不会的啊
package testt;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//分别代表证书、负数、还有0的个数
int zheng=0,fu=0,ling=0,input;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入10个数:");
for(int i = 0;i<10;i++){
input = scanner.nextInt();
if(input>0){
zheng++;
}else if(input<0){
fu++;
}else if(input==0){
ling++;
}
}
System.out.println("正数的个数:"+zheng+" 负数的个数:"+fu+" 零的个数:"+ling);
}
}