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 ...
随机推荐
- Windows Terminal (Preview)治好了cmd,powershell的癌症
前言 话说n年前,我想开发一款powershell麻将游戏,但是发现命令行下无法显示麻将牌这种特殊符号. 经过研究发现,这是4字节的utf16le字符串.而powershell依赖的渲染引擎,只能渲染 ...
- ICP&TPS:最近邻
经过了一段时间的研bai究gei...终于可以偷得几天闲了. 这里来补个档. 无论是ICP还是TPS,缺乏锚点的前提下.你总是要通过找另一个曲面的最近的点来实现你的work beimat:点数*3,f ...
- WPF 隐藏式控件
没用Popup用的面板控件,全部代码使用xaml的触发器. 代码: <Grid> <DockPanel> <StackPanel Background=" Do ...
- Linux RAID 磁盘管理
Linux RAID 磁盘管理 RAID工作模式介绍:https://www.cnblogs.com/xiangsikai/p/8441440.html 本章主要讲解 Linux下 RAID5 与 R ...
- 关于5G手机使用4G套餐扫盲
有些人说换5G手机用4G套餐不用5G套餐可以享受最高 300 mbps 的签约速率.在此我来给你们科普下. 5G套餐分为 500 mbps 和 1000 mbps 两种.且都享受优先接入,顺序是 10 ...
- WEB网站发布服务器IIS报错问题终极解决方案,查到问题点
4本次错误webservice发布新服务器后,出现此错误. 解决方法: 找到dmp文件 dmp文件是啥?自己百度.简单的说就是黑匣子,记录程序崩溃前的操作,那么如何找到这个黑匣子呢? 1.启动 Win ...
- IP 跟踪
#coding=utf-8import sysimport os import re import urllibimport subprocess def getlocation(ip): resul ...
- Linux文件共享服务 FTP,NFS 和 Samba
Linux 系统中,存储设主要有下面几种: DAS DAS 指 Direct Attached Storage,即直连附加存储,这种设备直接连接到计算机主板总线上,计算机将其识别为一个块设备,例如常见 ...
- liteos错误处理(十一)
1. 概述 1.1 基本概念 错误处理指用户代码发生错误时,系统调用错误处理模块的接口函数,完成上报错误信息,并调用用户自己的钩子函数,进行特定的处理. 错误处理模块实现OS内部错误码记录功能.OS内 ...
- 002-OpenStack-认证服务
OpenStack-认证服务 [基于此文章的环境]点我快速打开文章 1.安装和配置 控制节点(controller) 1.1 创库授权 keystone mysql CREATE DATABASE k ...