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. poj 2104 (划分树模板)

    Description You are working for Macrohard company in data structures department. After failing your ...

  2. 异常message:There is no database named cloudera_manager_metastore_canary_test_db_hive_hivemetastore

    NoSuchObjectException(message:There is no database named cloudera_manager_metastore_canary_test_db_h ...

  3. VC++使用CImage PNG转BMP图片透明背景处理

    PNG格式的图片是支持透明通道的,BMP格式的图片是没有透明通道的,所以当PNG格式的图片转换为BMP格式时,对于PNG图片的透明背景就需要进行特别的处理. VC++中的HBITMAP是支持透明色的, ...

  4. Join/remove server into/from windows domain PS script

    Join server into windows domain PS script $username = "ad-domain\admin" $Password = " ...

  5. c++ 公有继承的赋值兼容规则

    赋值兼容规则是指在需要基类对象的任何地方都可以使用公有派生类的对象来替代.通过公有继承,派生类得到了基类中除构造函数.析构函数之外的所有成员,而且所有成员的访问控制属性也和基类完全相同.这样,公有派生 ...

  6. python函数超时,用装饰器解决 func_timeout

    https://zhuanlan.zhihu.com/p/39743129 https://www.jianshu.com/p/a7fc98c7af4d https://ixyzero.com/blo ...

  7. fs.watch 爬坑

    上星期用 fs.watch 和 readline.createInterface 对pm2的合并日志做了监控,根据指定的错误信息重启服务 发现不管是手动vim编辑日志,还是等待日志自动输出. fs.w ...

  8. org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported解决!

    org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported解决 ...

  9. HDU1878 欧拉回路---(并查集+图论性质)

    http://acm.hdu.edu.cn/showproblem.php?pid=1878 欧拉回路 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  10. Hadoop之yarn调用机制

    1,Mapper方法:如果在map方法之前执行一些程序用setup,之后用cleanup.同理在Reducer方法中也有setup和cleanup. 2,map任务是并行执行,没有谁先谁后,如果是两个 ...