Find the maximum and minimum value

From , 5 Years ago, written in Java, viewed 64 times.
URL https://pastebin.vip/view/0c9ebb2d
  1. package jishu;
  2. public class test01 {
  3.         public static void main(String[] args) {
  4.                 int a[]={21,5,33,65,98,24,64};
  5.                 int n;
  6.                 int sum = 0;//声明和,并赋值
  7.                 int max=a[0];//假设第一位是最大值
  8.                 int min=a[0];//假设第一位是最小值
  9.                 for(n=0;n<7;n++){
  10.                         //如果第N位的数比max大,则将第N位的数覆给max。
  11.                         if(max<a[n])
  12.                                 max=a[n];
  13.                         if(min>a[n])
  14.                                 min=a[n];
  15.                         sum+=a[n];
  16.                 }
  17.                 System.out.println("和:"+sum+"最大值:"+max+"最小值"+min);
  18.         }
  19. }
  20.  

Reply to "Find the maximum and minimum value"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website