用java定义一个一维整型数组array={1,2,3,4,5,6,7,8,9,10},输出该数组元素之和、最大值、最小值。

如题所述

第1个回答  2015-05-28
public class Test{

public static void main(String args[]){
int score[] = null ;
score = new int[10] ;
for(int i = 0 ; i <
score.length ; i++){
score[i] = i
;
}
int max , min , sum ;
max = score[0] ;
min = score[0] ;
sum = 0 ;
for(int i = 0 ; i <
score.length ; i++){
if(max <
score[i]){
max
= score[i] ;
}
if(min >
score[i]){
min
= score[i] ;
}
sum +=
score[i] ;
}
System.out.println("max = " + max +
" min = " + min + " sum = " +
sum);本回答被提问者采纳
相似回答