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的更多相关文章

  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. 基于仿射的非刚体配准方法(i) 法向

    为啥闲呢,因为work干完了. 为啥补档呢,因为有新work了. 呃,因为新work让人自闭. 我现在干完了两部分.一是把最近邻的部分迁移过来. 二是求法向. 首先是给三个点,就能确定平面——因为是三 ...

  2. 我在生产项目里是如何使用Redis发布订阅的?(一)使用场景

    转载请注明出处! 导语 Redis是我们很常用的一款nosql数据库产品,我们通常会用Redis来配合关系型数据库一起使用,弥补关系型数据库的不足. 其中,Redis的发布订阅功能也是它的一大亮点.虽 ...

  3. 第三节: List类型的介绍、生产者消费者模式、发布订阅模式

    一. List类型基础 1.介绍 它是一个双向链表,支持左进.左出.右进.右出,所以它即可以充当队列使用,也可以充当栈使用. (1). 队列:先进先出, 可以利用List左进右出,或者右进左出(Lis ...

  4. Kubernetes Ingress 部署

    Kubernetes Ingress 部署 Pod与Ingress的关系• 通过service相关联• 通过Ingress Controller实现Pod的负载均衡- 支持TCP/UDP 4层和HTT ...

  5. Elasticsearch(ES) 下载&安装

    欢迎关注笔者的公众号: 小哈学Java, 每日推送 Java 领域干货文章,关注即免费无套路附送 100G 海量学习.面试资源哟!! 个人网站: https://www.exception.site/ ...

  6. .Net捕获网站异常信息记录操作日志

    第一步:在Global.asax文件下的Application_Error()中写入操作日志 /// <summary> /// 整个网站出现异常信息,都会执行此方法 /// </s ...

  7. mpvue小程序开发之 实现一个弹幕评论

    先上图 就是一个简单的弹幕发送功能 弹幕区的页面: <div class="content" v-show="doommData.length"> ...

  8. html跳转,获取get提交参数

    html跳转到html页面,url后面携带参数,可以通过脚本获取到url?test=value地址后的参数. 1.more.html 携带参数跳转到list.html,get提交参数 2.list.h ...

  9. 010.[转] maven的三大生命周期

    一.Maven的生命周期 Maven的生命周期就是对所有的构建过程进行抽象和统一.包含了项目的清理.初始化.编译.测试.打包.集成测试.验证.部署和站点生成等几乎所有的构建步骤. Maven的生命周期 ...

  10. linux(05) 编译安装py3

    一.编译安装python3 https://www.cnblogs.com/pyyu/p/9015317.html 1.下载python3的源码 cd /opt yum install wget -y ...