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

2024-12-01 07:11:30
推荐回答(1个)
回答1:

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);