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 ...
随机推荐
- js 价格 格式化 数字和金额
方法一: abs = function(val){ //金额转换 分->元 保留2位小数 并每隔3位用逗号分开 1,234.56 var str = (val/100).toFixed(2) + ...
- Spring源码系列 — Bean生命周期
前言 上篇文章中介绍了Spring容器的扩展点,这个是在Bean的创建过程之前执行的逻辑.承接扩展点之后,就是Spring容器的另一个核心:Bean的生命周期过程.这个生命周期过程大致经历了一下的几个 ...
- Mysql综述--数据是如何读存的?(2)
页的结构 页是一种InnoDB管理存储空间的基本单位,它一般大小在16kb左右.实际上存在着许多不同类型的页,我们这次主要介绍的页是用来存储数据的,也叫做索引页. 接下来看看索引页的结构图: 比较重要 ...
- Centos安装jdk1.8出现-bash: //usr/local/soft/jdk1.8.0_191/bin/javac: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录错误。
1.从来没有这么郁闷,之前安装都是好好的,自从将Centos升级到7.0版本,安装了jdk报了这个错误,也是郁闷的一毛,参考了一下百度的,记录一下.使用java命令还有java -version命令都 ...
- js变量--全局变量和局部变量
1.javaScript中在函数里声明的变量为局部变量,其余为全局变量. 2.javaScript没有块级元素
- c#编码注释
1 目录 2 前言... 3 2.1 编写目的... 3 2.2 适用范围... 4 3 命名规范... 4 3.1 命名约 ...
- 百度站长平台HTTPS认证所遇到的坑
坑1: 百度站长平台https认证失败,提示:请确保您网站的所有链接均支持https访问,且未使用不安全协议(如:SSL2.SSL3等协议). 解决办法: 1. 友情链接检查, 要检查所有的友情链接 ...
- pytest-Mark数据驱动
数据驱动 import pytest @pytest.mark.parametrize(("a", "b", "expected"), [ ...
- 结对编程作业(java)
结对对象:许峰铭 一.Github项目地址:https://github.com/Leungdc/Leungdc/tree/master/%E5%9B%9B%E5%88%99%E8%BF%90%E7% ...
- [b0016] python 归纳 (二)_静态方法和类方法
# -*- coding: UTF-8 -*- """ 测试 类的静态方法,类方法 @staticmethod @classmethod 总结: 1. self 指向类对 ...