写一个程序,输入5个数,然后请显示出其中正数,负数,0的个数。拜托各位前辈帮帮我,感谢Java

还有别的问题,有好心人吗,刚学java
3211395950

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

int pos = 0;
int neg = 0;
int zero = 0;

Scanner in = new Scanner(System.in);
for(int i = 0; i < 5; i++) {
int num = in.nextInt();
if(num == 0)
zero++;
else if (num < 0)
neg++;
else
pos++;
}
in.close();
System.out.println("正数个数:"+pos+"负数"+neg+" 0个数"+zero);

}
}

//望采纳。
温馨提示:内容为网友见解,仅供参考
第1个回答  2015-10-11
import java.util.Scanner;
public class test {
public static void main(String[] args) {
int[] count = new int[3];
int temp;
Scanner s = new Scanner(System.in);
for(int i=0;i<5;i++){
temp=s.nextInt();
if(temp<0){
count[0]++;
}
else if(temp==0){
count[1]++;
}
else if(temp>0){
count[2]++;
}
}

System.out.println("负数:"+count[0]+" 0:"+count[1]+" 正数:"+count[2]);
}
}
相似回答