1. 程式人生 > >求數組元素的最大值

求數組元素的最大值

rgs ++ 分享 length int pack alt system i++

package com.imooc.array;

public class ArrayDemo3 {

	public static void main(String[] args) {
		//求數組元素的最大值
		int[] a={34,23,78,56,31};
		int max=a[0];
		for(int i=1;i<a.length;i++){
			if(max<a[i]){
				max=a[i];
			}
		}
		System.out.println("數組元素的最大值為"+max);
	}

}

  技術分享圖片

同理求最小值、鍵盤輸入值最值

求數組元素的最大值