배열 활용

  1. 배열의 요소 중에서 최대값과 최소값 찾기

class Ex5_3 { 
	public static void main(String[] args) { 
		int[] score = { 79, 88, 91, 33, 100, 55, 95 }; 

		int max = score[0]; 
		int min = score[0]; 

		for(int i=1; i < score.length;i++) {
			if(score[i] > max) { 
				max = score[i]; 
			} else if(score[i] < min) { 
				min = score[i]; 
			} 
		} // end of for 

		System.out.println("최대 :" + max);       
		System.out.println("최소 :" + min);       
	} // end of main 
} // end of class

2. shuffle(섞기) : 숫자 섞기, 로또번호 생성

Last updated

Was this helpful?