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 ...
随机推荐
- awk的使用备忘
[转]http://www.cnblogs.com/mydomain/archive/2012/09/24/2699467.html awk引用外部变量 一.用awk 有以下几种方法去调用变量: ...
- qt 5 数据库操作(mysql)
其实大家都知道,QT5以上的都自带了数据库驱动,所以呢,基本上可以直接使用,于是如果想知道怎么连接数据库,请参考这位大神写的.http://qtdebug.com/DB-AccessMySQL.htm ...
- CODEVS 1132 瑞士轮
题目描述 Description 背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平, ...
- DOS下删除整个目录及下属所有文件夹及文件最好用的命令
Windows XP以上的版本,在使用DOS命令模式下删除目录(目录就是档案总管中所谓的资料夹)不是用 deltree,而是用 rmdir 指令. 在Windows XP.2000.NT下都可用rmd ...
- 使用.net 的Chart控件绘制曲线图
在进行软件开发过程中我们可能会碰到需要生成图表的情况,在.NET中以前经常用GDI去绘制,虽然效果也不错,自从.NET 4.0开始,专门为绘制图表而生的Chart控件出现了,有了它,就可以轻松的绘制你 ...
- char型字符串(数组)与string型字符串 指针与引用
一.常指针: int *const p; //指针不可改变,但是指针指向的数据可以改变. 指向常量的指针: const int *p; //指针可以改变,但是指针指向的数据不可以改变. 指 ...
- bool([x]) 将x转换为Boolean类型
>>> a = 1 >>> b = 0 >>> c = "None" >>> d = bool(a) > ...
- BZOJ 3998 [TJOI 2015] 弦论 解题报告
这是一道后缀自动机经典题目. 对于 $t=0$ 的情况:每个节点都代表一个子串,所以我们给每个节点的 $Size$ 都记为 $1$, 对于 $t=1$ 的情况:我们只给 $last$ 节点的 $Siz ...
- Hex、bin、axf、elf格式文件小结
转自Hex.bin.axf.elf格式文件小结 一.HEX Hex文件,一般是指Intel标准的十六进制文件.Intelhex 文件常用来保存单片机或其他处理器的目标程序代码.它保存物理程序存储区中的 ...
- 将一个字符串映射为一个Delphi页面控件属性名(通过FindComponent和GetPropInfo找到这个控件指针)
uses TypInfo; function TForm1.SetControlProp(ComStr, value: string): boolean; var ComName, ComProp: ...