首页 > 其他 > 详细

打印出大小值

时间:2017-04-12 11:51:38      阅读:221      评论:0      收藏:0      [点我收藏+]

第八章

注意事项:

必须要给max min赋值

要创建一个数组

 

 

public class Demo01 {

 public static void main(String[]args) {
  Scanner input=new Scanner(System.in);
  int [] scores=new int[5];
  int max=0;
  int min=0;
  for (int i = 0; i < scores.length; i++) {
   System.out.println("请输入"+(i+1)+"位同学的成绩:");
   scores[i]=input.nextInt();
  }
  min=scores[0];
  max=scores[0];
  
  for (int i = 0; i < scores.length; i++) {
   if (scores[i]>max) {
    max=scores[i];
    
   }
  }

  for (int i = 0; i < scores.length; i++) {
  if (scores[i]<min) {
   min=scores[i];
   
   
   
  } 
  }
  System.out.println("最高分:"+max);
  System.out.println("最低分:"+min);
  
  
 }
}

打印出大小值

原文:http://www.cnblogs.com/cj953865288/p/6697869.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!