统计正数和负数的个数,然后计算这些数的平均值 Exercise05_01
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的更多相关文章
- java,从键盘输入个数不确定的整数,并判断输入的正数和负数的个数,输入0时结束程序。
package study01; import java.util.Scanner; public class Test { public static void main(String[] args ...
- C#设置textBox只能输入数字(正数,负数,小数)简单实现
/* *设置textBox只能输入数字(正数,负数,小数) */ public static bool NumberDotTextbox_KeyPress(object sender, KeyPres ...
- Javascript 统计复选框选中个数
var checked = document.getElementsByName("checked_c[]"); var checked_counts = 0; for(var i ...
- Linux 统计文件夹下文件个数
查看统计当前目录下文件的个数,包括子目录里的. ls -lR| grep "^-" | wc -l Linux下查看某个目录下的文件.或文件夹个数用到3个命令:ls列目录.用gre ...
- 学c语言做练习之统计文件中字符的个数
统计文件中字符的个数(采用命令行参数) #include<stdio.h> #include<stdlib.h> int main(int argc, char *argv[] ...
- 题目--统计一行文本的单词个数(PTA预习题)
PTA预习题——统计一行文本的单词个数 7-1 统计一行文本的单词个数 (15 分) 本题目要求编写程序统计一行字符中单词的个数.所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可以 ...
- Linux上统计文件夹下文件个数以及目录个数
对于linux终端用户而言,统计文件夹下文件的多少是经常要做的操作,于我而言,我会经常在谷歌搜索一个命令,“如何在linux统计文件夹的个数”,然后点击自己想要的答案,但是有时候不知道统计文件夹命令运 ...
- 统计无向图中三角形的个数,复杂度m*sqrt(m).
统计无向图中三角形的个数,复杂度m*sqrt(m). #include<stdio.h> #include<vector> #include<set> #inclu ...
- 给出一个string字符串,统计里面出现的字符个数
给出一个string字符串,统计里面出现的字符个数 解决方案: 使用algorithm里面的count函数,使用方法是count(begin,end,'c'),其中begin指的是起始地址,end指的 ...
随机推荐
- java过滤器和监听器详解
过滤器 1.Filter工作原理(执行流程) 当客户端发出Web资源的请求时,Web服务器根据应用程序配置文件设置的过滤规则进行检查,若客户请求满足过滤规则,则对客户请求/响应进行拦截,对请求头和请求 ...
- Install the AWS Command Line Interface on Linux
Install the AWS Command Line Interface on Linux You can install the AWS Command Line Interface and i ...
- Java Error: Failed to validate certificate. The application will not be executed
Hi, last week a customer had the problem that he wants to connect to the administration interface of ...
- CentOS 6.5 Linux 安装 openoffice
资源准备: Apache_OpenOffice_4.1.4_Linux_x86-64_install-rpm_zh-CN.tar.gz 编译安装: 本人资源包放在 /opt/moudles 中, 解压 ...
- SQL优化单表案例
数据准备: -- 创建数据库 mysql> create database db_index_case; Query OK, row affected (0.00 sec) -- 查看数据库 m ...
- javascript简易下拉菜单效果
JS代码: window.onload=function(){ var oDiv=document.getElementById('navMenu'); var aUl=oDiv.getElement ...
- unity中绘制战争迷雾
接上一篇中说的游戏,我们已经实现了client.host上的一个物体可见不可见的行为.之后我们可以加入类似检查两个单位之间的距离.或是两个单位之间有无阻挡物来进一步实现游戏机制. 在这篇随笔中我会首先 ...
- jupyter、flask、tornado、djiango安装
安装了pip包的话直接使用: 1.安装jupyter:pip install jupyter 2.安装flask: pip install flask 3.安装tornado:pip install ...
- bzoj 3212 线段树
裸的线段树 /************************************************************** Problem: User: BLADEVIL Langua ...
- go的websocket实现
websocket分为握手和数据传输阶段,即进行了HTTP握手 + 双工的TCP连接 RFC协议文档在:http://tools.ietf.org/html/rfc6455 握手阶段 握手阶段就是普通 ...