HW4.1

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的更多相关文章
- HW4.46
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW4.45
public class Solution { public static void main(String[] args) { int count = 0; for(int i = 1; i < ...
- HW4.44
public class Solution { public static void main(String[] args) { double randX; double randY; int hit ...
- HW4.43
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW4.42
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW4.41
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW4.40
public class Solution { public static void main(String[] args) { long positiveSide = 0; long negativ ...
- HW4.39
public class Solution { public static void main(String[] args) { double sum; double baseSalary = 500 ...
- HW4.38
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- HW4.37
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
随机推荐
- python通过webservice连接cmdbuild
cmdbuild的部署可以查看文章:http://20988902.blog.51cto.com/805922/1541289 部署成功后,访问http://192.168.1.1:8080/cmdb ...
- 【BZOJ】1088: [SCOI2005]扫雷Mine
1088: [SCOI2005]扫雷Mine Description 相 信大家都玩过扫雷的游戏.那是在一个n*m的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了,“余”人国流行起了一种简单的 ...
- Linux命令总结(转载)
转子:http://www.cnblogs.com/CGDeveloper/archive/2011/05/27/2060009.html 昨天看了一个教程,关于Linux命令的,本来以为当是复习随便 ...
- Convert.ToString和ToString的区别
Convert.ToString能处理字符串为null的情况,不抛出异常. ToString方法不能处理字符串为null的情况,会抛出异常.如:“未将对象引用设置到对象的实例”.
- Event Aggregator
/** * Created with JetBrains WebStorm. * User: 宇乔 * Date: 13-8-2 * Time: 下午3:01 * To change this tem ...
- 对敏捷开发的误解(转自MBAlib)
对敏捷开发的误解 误解一:敏捷对人的要求很高 很多人在尝试实施敏捷时说:敏捷对人的要求太高了,我们没有这样的条件,我们没有这样的人,因此我们没法敏捷.可是,敏捷对人的要求真的那么高么? 软件归根到底还 ...
- Temporary Post Used For Theme Detection (da655c32-bc15-41ad-bf89-e76c1ec1bea7 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)
This is a temporary post that was not deleted. Please delete this manually. (997facfe-d420-4437-a222 ...
- ExtJS4.2学习(15)树形表格(转)
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-27/185.html --------------- ...
- MongoDB实战指南(一):大数据与云计算
1.1 什么大数据 具体来说,大数据技术涉及到数据的创造,存储,获取和分析,大数据的主要特点有下面几个: 数据量大.一个典型的PC机载2000年前后其存储空间可能有10GB,今天facebook一天增 ...
- 学习kernel编程的建议
我把我学习kernel编程的过程介绍给大家,希望大家有个参考. 学习kernel编程需要阅读大量的kernel方面的书籍,在此我列举一下我读过的kernel书籍(按时间先后顺序),并给一些建议. 1. ...