首页 > 代码库 > IO-03. 求整数均值
IO-03. 求整数均值
本题要求编写程序,计算4个整数的和与平均值。题目保证输入与输出均在整型范围内。
输入格式:
输入在一行中给出4个整数,其间以空格分隔。
输出格式:
在一行中按照格式“Sum = 和; Average = 平均值”顺序输出和与平均值,其中平均值精确到小数点后1位。
输入样例:1 2 3 4输出样例:
Sum = 10; Average = 2.5
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int a = input.nextInt(); int b = input.nextInt(); int c = input.nextInt(); int d = input.nextInt(); double Average = (double)(a+b+c+d)/4; System.out.print("Sum = "+(a+b+c+d)+"; "+"Average = "+Average); }}
IO-03. 求整数均值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。