1. public class Solution {
  2. public static void main(String[] args) {
  3. Scanner ip = new Scanner(System.in);
  4. double input = ;
  5. int count = ;
  6. double sum = ;
  7. while (input != -) {
  8. System.out.print("Enter input:(-1 to stop): ");
  9. input = ip.nextDouble();
  10. if (input != -) {
  11. sum = sum + input;
  12. ++count;
  13. }
  14. }
  15. System.out.println("Averager of " + count + " numbers is " + (sum / count) + " and its sum: " + sum);
  16. ip.close();
  17. }
  18. }
  19.  
  20. OUTPUT:
  21. Enter input:(- to stop):
  22. Enter input:(- to stop):
  23. Enter input:(- to stop):
  24. Enter input:(- to stop): -
  25. Averager of numbers is 20.0 and its sum: 60.0

find sum and average of n numbers的更多相关文章

  1. The Sum of 0 for four numbers(拆解加二分思想)

    个人心得:单纯用二分法一直超时,后面发现我的那种方法并没有节省多少时间,后面看了大神的代码,真的是巧妙, 俩个数组分别装a+b,c+d.双指针一个指向最后,从第一个开始想加,加到刚好大于0停止,再看是 ...

  2. bootstrap table footerFormatter用法 统计列求和 sum、average等

    其实上一篇blog里已经贴了代码,简单解释一下吧: 1.showFooter: true,很重要,设置footer显示: $(cur_table).bootstrapTable({ url: '/et ...

  3. python修饰器各种实用方法

    This page is meant to be a central repository of decorator code pieces, whether useful or not <wi ...

  4. 【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 ...

  5. PAT (Advanced Level) 1108. Finding Average (20)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  6. Pat1108: Finding Average

    1108. Finding Average (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The b ...

  7. A1108. Finding Average

    The basic task is simple: given N real numbers, you are supposed to calculate their average. But wha ...

  8. PAT甲题题解-1108. Finding Average (20)-字符串处理

    求给出数的平均数,当然有些是不符合格式的,要输出该数不是合法的. 这里我写了函数来判断是否符合题目要求的数字,有点麻烦. #include <iostream> #include < ...

  9. PAT 1108 Finding Average [难]

    1108 Finding Average (20 分) The basic task is simple: given N real numbers, you are supposed to calc ...

随机推荐

  1. Windows Terminal (Preview)治好了cmd,powershell的癌症

    前言 话说n年前,我想开发一款powershell麻将游戏,但是发现命令行下无法显示麻将牌这种特殊符号. 经过研究发现,这是4字节的utf16le字符串.而powershell依赖的渲染引擎,只能渲染 ...

  2. ICP&TPS:最近邻

    经过了一段时间的研bai究gei...终于可以偷得几天闲了. 这里来补个档. 无论是ICP还是TPS,缺乏锚点的前提下.你总是要通过找另一个曲面的最近的点来实现你的work beimat:点数*3,f ...

  3. WPF 隐藏式控件

    没用Popup用的面板控件,全部代码使用xaml的触发器. 代码: <Grid> <DockPanel> <StackPanel Background=" Do ...

  4. Linux RAID 磁盘管理

    Linux RAID 磁盘管理 RAID工作模式介绍:https://www.cnblogs.com/xiangsikai/p/8441440.html 本章主要讲解 Linux下 RAID5 与 R ...

  5. 关于5G手机使用4G套餐扫盲

    有些人说换5G手机用4G套餐不用5G套餐可以享受最高 300 mbps 的签约速率.在此我来给你们科普下. 5G套餐分为 500 mbps 和 1000 mbps 两种.且都享受优先接入,顺序是 10 ...

  6. WEB网站发布服务器IIS报错问题终极解决方案,查到问题点

    4本次错误webservice发布新服务器后,出现此错误. 解决方法: 找到dmp文件 dmp文件是啥?自己百度.简单的说就是黑匣子,记录程序崩溃前的操作,那么如何找到这个黑匣子呢? 1.启动 Win ...

  7. IP 跟踪

    #coding=utf-8import sysimport os import re import urllibimport subprocess def getlocation(ip): resul ...

  8. Linux文件共享服务 FTP,NFS 和 Samba

    Linux 系统中,存储设主要有下面几种: DAS DAS 指 Direct Attached Storage,即直连附加存储,这种设备直接连接到计算机主板总线上,计算机将其识别为一个块设备,例如常见 ...

  9. liteos错误处理(十一)

    1. 概述 1.1 基本概念 错误处理指用户代码发生错误时,系统调用错误处理模块的接口函数,完成上报错误信息,并调用用户自己的钩子函数,进行特定的处理. 错误处理模块实现OS内部错误码记录功能.OS内 ...

  10. 002-OpenStack-认证服务

    OpenStack-认证服务 [基于此文章的环境]点我快速打开文章 1.安装和配置 控制节点(controller) 1.1 创库授权 keystone mysql CREATE DATABASE k ...