import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);

         System.out.print("Enter an int value, the program exits if the input is 0: ");
         int inputValue = input.nextInt();
         int count = 1;

         int positive = 0;
         int negative = 0;
         if(inputValue > 0)
             positive = 1;
         else if(inputValue < 0)
             negative = 1;

         int sum = inputValue;

         while(inputValue != 0)
         {
             System.out.print("Enter an int value, the program exits if the input is 0: ");
             inputValue = input.nextInt();
             count++;
             sum += inputValue;
             if(inputValue > 0)
                 positive++;
             else if(inputValue < 0)
                 negative++;
         }

         float average = (float)(sum * 1.0) / count;

         System.out.println("The number of positives is " + positive);
         System.out.println("The number of negatives is " + negative);
         System.out.println("The total is " + count);
         System.out.println("The average is " + average);
     }
 }

HW4.1的更多相关文章

  1. HW4.46

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  2. HW4.45

    public class Solution { public static void main(String[] args) { int count = 0; for(int i = 1; i < ...

  3. HW4.44

    public class Solution { public static void main(String[] args) { double randX; double randY; int hit ...

  4. HW4.43

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  5. HW4.42

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  6. HW4.41

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  7. HW4.40

    public class Solution { public static void main(String[] args) { long positiveSide = 0; long negativ ...

  8. HW4.39

    public class Solution { public static void main(String[] args) { double sum; double baseSalary = 500 ...

  9. HW4.38

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  10. HW4.37

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

随机推荐

  1. leetcode解题—Longest Palindromic Substring

    题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  2. Python prettytable的使用方法

    Python prettytable的使用方法 prettytable可以整齐地输出一个表格信息: +-----------+------+------------+----------------- ...

  3. Junit4.12、Hamcrest1.3、Eclemma的安装和使用

    1. Junit4.12和Hamcrest1.3的安装过程 步骤: 网上下载Junit和Hamcrest包文件,保存在本地. 新建Java项目命名为Triangle,在Eclipse菜单栏选择项目(P ...

  4. 如何获得iphone设备的剩余空间

    在手机终端开发的时候,我们需要关注手机剩余空间,因为手机不像电脑一样空间宽裕,当设备空间比较少得时候需要释放空间. 用法:先引入头文件 #include <sys/param.h> #in ...

  5. mysql的错误:The server quit without updating PID file /usr/local/mysql/data/door.pid).

    mysql错误解决: 先 参考:http://www.jb51.net/article/48625.htm 参考第四条: mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打 ...

  6. 异常: http://www.ly.com/news/visa.html: java.io.IOException: unzipBestEffort returned null

    nutch 运行时异常: http://www.ly.com/news/visa.html: java.io.IOException: unzipBestEffort returned null 参考 ...

  7. HDU 1253 胜利大逃亡(三维BFS)

    点我看题目 题意 : 中文题不详述. 思路 :因为还牵扯到层的问题,所以用三维的解决,不过这个还是很简单的BFS,六个方向搜一下就可以了,一开始交的时候老是超时,怎么改都不对,后来看了一个人写的博客, ...

  8. 怎么修改tomcat默认访问首页

    一般情况下安装好tomcat之后我们的默认访问首页是index了,但我们如果要修改或增加一个默认首页,我们可参考下面办法来解决. 通过 ip:port 访问到的是 tomcat 的管理页面,其他常规部 ...

  9. flash 类和对象的关系

    每个具体的对象后面都隐藏着抽象的类. flash 中as3.0中所有的类,都是为了创建对象所用的.反过来,所创建的任何具体对象都隐藏着抽象的类. 类可以把它看做函数,类的属性是函数的数据,类的方法是函 ...

  10. JMP软件中的晶圆图( Wafer Map)分析

    关键词:芯片 良率分析 晶圆图 质量管理 JMP Minitab 半导体芯片的生产,简单来讲,是将电路通过各种复杂的物理化学方法制作到晶圆上,在生产的最后阶段会进行不同电性功能的测试以确保产品的功能性 ...