JAVA 上机作业4.1

/*  
* Copyright (c) 2015,烟台大学计算机学院  
* All right reserved.  
* 文件名:test1.java 
* 作者:柴银平  
* 完成时间:2015年10月6日  
* 版本号:v1.0  
*  
* 问题描述:输入几个整数,以零来结束输入,统计其中的正负数个数,冰球和,还算出平均值。
*  
* 程序输入:输入几个整数 
* 程序输出: 输出正负数个数,总和,平均值
*/
import java.util.Scanner;

public class test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input=new Scanner(System.in);
		int a,p=0,n=0,total=0,i=0;
		double average;
		System.out.println("Enter an int value,the program exits if the input is 0:");
		a=input.nextInt();
		while (a!=0)
		{
			if (a>0)
				p++;
			if (a<0)
				n++;
			total+=a;
		    a=input.nextInt();
			i++;
		}
		average=(double)total/i;
		System.out.println("The number of positives is "+p);
		System.out.println("The number of negatives is "+n);
		System.out.println("The total is "+total);
		System.out.println("The average is "+average);
	}
}


测试图示:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值