码迷,mamicode.com
首页 > 编程语言 > 详细

Java练习题02

时间:2015-09-20 01:36:00      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

问题:

编程求一个整数数组的最大值、最小值、平均值和所有元素的和。

代码:

public class Page99{

????public static void main(String args[]){

????????int NumArray[]=new int[]{32,94,15,86,1533,-98,143,140,11,39,65};

????????int Average = 0;

????????int Sum = 0;

????????for(int j = 0; j < NumArray.length; j++){

????????????for(int i = j; i < NumArray.length; i++){

????????????????if(NumArray[j] >= NumArray[i]){

????????????????????int t = NumArray[i];

????????????????????NumArray[i] = NumArray[j];

????????????????????NumArray[j] = t;

????????????????}????

????????????????

????????????}

????????}

????????

????????for(int j = 0; j < NumArray.length; j++){

????????????Sum = NumArray[j] + Sum;

????????}

????????Average = Sum/(NumArray.length);

????????System.out.print("最小值:");????

????????System.out.println(NumArray[0]);

????????System.out.print("最大值:");????

????????System.out.println(NumArray[NumArray.length-1]);

????????System.out.print(" 和:");????

????????System.out.println(Sum);

????????System.out.print("平均值:");????

????????System.out.print(Average);

?

????}

};

Java练习题02

标签:

原文地址:http://www.cnblogs.com/iucforever/p/4822665.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!