用java定义一个一维整型数组array={1,2,3,4,5,6,7,8,9,10},输出该数组元素之和、最大值、最小值。
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);
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);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询