find sum and average of n numbers
public class Solution {
public static void main(String[] args) {
Scanner ip = new Scanner(System.in);
double input = ;
int count = ;
double sum = ;
while (input != -) {
System.out.print("Enter input:(-1 to stop): ");
input = ip.nextDouble();
if (input != -) {
sum = sum + input;
++count;
}
}
System.out.println("Averager of " + count + " numbers is " + (sum / count) + " and its sum: " + sum);
ip.close();
}
}
OUTPUT:
Enter input:(- to stop):
Enter input:(- to stop):
Enter input:(- to stop):
Enter input:(- to stop): -
Averager of numbers is 20.0 and its sum: 60.0
find sum and average of n numbers的更多相关文章
- The Sum of 0 for four numbers(拆解加二分思想)
个人心得:单纯用二分法一直超时,后面发现我的那种方法并没有节省多少时间,后面看了大神的代码,真的是巧妙, 俩个数组分别装a+b,c+d.双指针一个指向最后,从第一个开始想加,加到刚好大于0停止,再看是 ...
- bootstrap table footerFormatter用法 统计列求和 sum、average等
其实上一篇blog里已经贴了代码,简单解释一下吧: 1.showFooter: true,很重要,设置footer显示: $(cur_table).bootstrapTable({ url: '/et ...
- python修饰器各种实用方法
This page is meant to be a central repository of decorator code pieces, whether useful or not <wi ...
- 【leetcode】Sum Root to Leaf Numbers(hard)
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
- PAT (Advanced Level) 1108. Finding Average (20)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- Pat1108: Finding Average
1108. Finding Average (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The b ...
- A1108. Finding Average
The basic task is simple: given N real numbers, you are supposed to calculate their average. But wha ...
- PAT甲题题解-1108. Finding Average (20)-字符串处理
求给出数的平均数,当然有些是不符合格式的,要输出该数不是合法的. 这里我写了函数来判断是否符合题目要求的数字,有点麻烦. #include <iostream> #include < ...
- PAT 1108 Finding Average [难]
1108 Finding Average (20 分) The basic task is simple: given N real numbers, you are supposed to calc ...
随机推荐
- Java 银联云闪付对接记录
一开始盲目找资料走了弯路: 还是从银联给的官方文档入手最高效: 附件3:云闪付业务商户入网服务指引.pdf http://tomas.test.upcdn.net/pay/%E9%99%84%E4%B ...
- golang两种在for循环中使用goroutine的错误形式
1. 闭包中使用循环体中变化的量 platground链接: https://play.golang.org/p/6x6_tuQNjUO type Value struct{ val int } fu ...
- Python基础23(习惯)
自己写的大段代码,注释分为两种: 一种 # 顶格写,为后注释," Ctrl+/ " 一种为边写边注释
- 链表逆序,java实现
package com.cskaoyan.linkedlist; //反转数组 public class LinkedListDemo2 { public static Node reverse(No ...
- Linux文件共享服务 FTP,NFS 和 Samba
Linux 系统中,存储设主要有下面几种: DAS DAS 指 Direct Attached Storage,即直连附加存储,这种设备直接连接到计算机主板总线上,计算机将其识别为一个块设备,例如常见 ...
- CSS 选择器大全
在CSS中,选择器是用于选择要设置样式的元素的模式. 选择器 例子 描述 .class .intro 选择class=“intro”的所有元素 #id #firstname 选择id=“firstna ...
- MySQL的select(极客时间学习笔记)
查询语句 首先, 准备数据, 地址是: https://github.com/cystanford/sql_heros_data, 除了id以外, 24个字段的含义如下: 查询 查询分为单列查询, 多 ...
- [日期工具分享][Shell]为特定命令依次传入顺序日期执行
[日期工具分享][Shell]为特定命令依次传入顺序日期执行 使用方式: <本脚本文件名(必要时需要全路径)> <要执行的命令所在的文件名> <开始日期> < ...
- Windows下面startup.bat启动Tomcat偶发死锁问题
Windows下面startup.bat启动Tomcat时,因为日志都打印到了cmd里面,存在偶发卡死Tomcat的问题,该问题确认是Windows系统的问题,而且一直没有解决.解决的办法是把日志重定 ...
- 8. [mmc subsystem] host(第二章)——sdhci
一.sdhci core说明 1.sdhci说明 具体参考<host(第一章)--概述> SDHC:Secure Digital(SD) Host Controller,是指一套sd ho ...