不知道怎么了,今天坐在电脑前面就想写写代码了。废话不多说。
正如题目所说:输入一堆数值,求平均值,最大值,最小值,和
代码直接粘上:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30Scanner input = new Scanner(System.in); String [] str = input.nextLine().split(" "); int [] count = new int[str.length]; for (int i = 0; i < str.length; i++) { count[i] = Integer.parseInt(str[i]); } //求最小值 int min = 0,max = 0,sum = count[0]; if(count[0] > count[1]){ max = count[0]; min = count[1]; }else{ max = count[1]; min = count[0]; } for (int i = 1; i < count.length; i++) { if(min > count[i]){ min = count[i]; } if(max < count[i]){ max = count[i]; } sum += count[i]; } System.out.println("最小值是:" + min); System.out.println("最大值是:" + max); System.out.println("和是:" + sum); System.out.println("平均值是:" + sum * 1.0 / count.length );
ok,就是这样了。
最后
以上就是粗暴铃铛最近收集整理的关于输入一堆数值,求平均值,最大值,最小值,和的全部内容,更多相关输入一堆数值内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复