본문 바로가기

JAVA/Example

배열 항목에서 최대값을 출력하는 코드 만들기

package homework;

public class Var7 {

	public static void main(String[] args) {
		//배열의 최대값
		int[] array = { 1, 5, 3, 8, 2} ;
		int max=0;
		for(int x:array){
			if(x>max)max=x;
		}System.out.println(max);
	}
}