JAVA 프로그래밍

문제

제네릭 클래스 ArrayList 및 Collections를 바탕으로 점수 및 단어를 정렬하는 문제입니다 이를 해결하는 프로그램을 작성하세요 
86 89 90
apple banana carrot 

알고리즘 설계

프로그램 시작 
   먼저, 점수 정렬 후 출력
   단어 정렬 후 출력
프로그램 종료

프로그램 구현

     
 
 ※ 단계별 점검: A키(이전), D키(다음) 
 
	// 파일명 : ./Chapter20/GenericTest.java
	import java.util.*;
		  
	public class GenericTest {
		// 프로그램 시작 	
1		public static void main( String[] args ) {
			// 먼저, 점수 정렬 후 출력   
			ArrayList<Integer> scores = new ArrayList<>();
			scores.add( 90 );
			scores.add( 89 );
			scores.add( 86 );
2			Collections.sort( scores );
			for( int i = 0; i < scores.size(); i++ )
			    System.out.print( scores.get(i) + " "  );
3			System.out.println();
		  
			// 단어 정렬 후 출력  
			ArrayList<String> words = new ArrayList<>();
			words.add( "carrot" );
			words.add( "banana" );
			words.add( "apple" );
4			Collections.sort( words );
			for( int i = 0; i < words.size(); i++ )
			    System.out.print( words.get(i) + " "  );
		  
		// 프로그램 종료 	
5		}
	}

실행 순서 확인