import java.util.Scanner;
/**
* @author 冰樱梦
*
*
*/
public class Exercise05_01{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
int positives=0,negatives=0,number,sum=0;
double total=0,average=0;
while(true){
System.out.println("Enter an integer, the input ends if it is 0:");
number=input.nextInt();
total+=number;
if(total==0){
System.out.println("No number are entered except 0");
break;
}
else {
if(number>0) positives++;
if(number<0) negatives++;
sum++;
if(number==0){
average=total/sum;
System.out.println("The number of positives is " + positives);
System.out.println("The number of negatives is " + negatives);
System.out.println("The total is " + total);
System.out.println("The average is " + average);
}
} } }
}

统计正数和负数的个数,然后计算这些数的平均值 Exercise05_01的更多相关文章

  1. java,从键盘输入个数不确定的整数,并判断输入的正数和负数的个数,输入0时结束程序。

    package study01; import java.util.Scanner; public class Test { public static void main(String[] args ...

  2. C#设置textBox只能输入数字(正数,负数,小数)简单实现

    /* *设置textBox只能输入数字(正数,负数,小数) */ public static bool NumberDotTextbox_KeyPress(object sender, KeyPres ...

  3. Javascript 统计复选框选中个数

    var checked = document.getElementsByName("checked_c[]"); var checked_counts = 0; for(var i ...

  4. Linux 统计文件夹下文件个数

    查看统计当前目录下文件的个数,包括子目录里的. ls -lR| grep "^-" | wc -l Linux下查看某个目录下的文件.或文件夹个数用到3个命令:ls列目录.用gre ...

  5. 学c语言做练习之​统计文件中字符的个数

    统计文件中字符的个数(采用命令行参数) #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv[] ...

  6. 题目--统计一行文本的单词个数(PTA预习题)

    PTA预习题——统计一行文本的单词个数 7-1 统计一行文本的单词个数 (15 分) 本题目要求编写程序统计一行字符中单词的个数.所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可以 ...

  7. Linux上统计文件夹下文件个数以及目录个数

    对于linux终端用户而言,统计文件夹下文件的多少是经常要做的操作,于我而言,我会经常在谷歌搜索一个命令,“如何在linux统计文件夹的个数”,然后点击自己想要的答案,但是有时候不知道统计文件夹命令运 ...

  8. 统计无向图中三角形的个数,复杂度m*sqrt(m).

    统计无向图中三角形的个数,复杂度m*sqrt(m). #include<stdio.h> #include<vector> #include<set> #inclu ...

  9. 给出一个string字符串,统计里面出现的字符个数

    给出一个string字符串,统计里面出现的字符个数 解决方案: 使用algorithm里面的count函数,使用方法是count(begin,end,'c'),其中begin指的是起始地址,end指的 ...

随机推荐

  1. 移动端浏览器touch事件的研究总结

    $("body").on("touchstart", function(e) {     e.preventDefault();     startX = e. ...

  2. elk,centos7,filebeat,elasticsearch-head集成搭建

    1.安装 elasticsearch-5.2.2.tar.gz cd elasticsearch-5.2.2/bin ./elasticsearch -Ecluster.name=my_cluster ...

  3. 播放video

    <html> <head> <title> four in one vedio</title> <style type="text/cs ...

  4. Ubuntu 编译Webkit --gtk

    转载自:http://www.linuxidc.com/Linux/2011-10/44809.htm webkit是一个浏览器内核,google的chrome就是基于它的,下面介绍一下如何在Ubun ...

  5. windows远程桌面访问ubuntu12.04

    转载自 : http://blog.csdn.net/shuzui1985/article/details/7592569 1.dashboard----桌面共享 我们共享所使用的协议是rdp,所以我 ...

  6. 理解JWT(JSON Web Token)认证及python实践

    原文:https://segmentfault.com/a/1190000010312468?utm_source=tag-newest 几种常用的认证机制 HTTP Basic Auth HTTP ...

  7. xcode 10 新特性

    这里主要介绍一下Xcode10 版本主要更新的内容.随着iOS12的发布,Xcode10已经可以从Mac App Store下载.Xcode10包含了iOS12.watchOS 5.macOS10.1 ...

  8. leetcode-501. Find Mode in Binary Search Tree

    Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred ...

  9. IDEA中如何使用svn

    1.安装tortoiseSVN客户端时,这里一定要勾选上,否则使用时会报错. 2.安装好之后,想启用idea的SVN插件还需要在idea配置一下,file - setting 按钮打开设置界面 或者( ...

  10. 稀疏编码概率解释(基于1996年Olshausen与Field的理论 )

    一.Sparse Coding稀疏编码 稀疏编码算法是一种无监督学习方法,它用来寻找一组“超完备”基向量来更高效地表示样本数据.稀疏编码算法的目的就是找到一组基向量 ,使得我们能将输入向量 表示为这些 ...