import java.util.Scanner;
public class Posinega {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("enter an int value,the programing exits if input is 0");
int a=input.nextInt();
int posi=0,nega=0,num=0,sum=0;
while(a!=0)
{
if(a>0)
posi++;
else
nega++;
num++;
sum+=a;
a=input.nextInt();
}
System.out.println("The number of positive is "+posi);
System.out.println("The number of negative is "+nega);
System.out.println("The total is "+num);
System.out.println("The average is "+(double)sum/num);
}
}
Java求任意一组数正数负数平均数的个数
最新推荐文章于 2022-09-25 22:58:15 发布