求数组元素的最大值

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

}

  

 

同理求最小值、键盘输入值最值

 

posted @ 2017-12-26 16:18  振华213  阅读(488)  评论(0编辑  收藏  举报