JAVA 프로그래밍

문제

제네릭 메서드를 바탕으로 점수 및 단어를 정렬하는 문제입니다 실행순서를 클릭하세요 
86 89 90
apple banana carrot 

프로그램 코드

	public class GenericMethodMain
	{
Fb		public static <T extends Comparable<T>> void sort( T[] list ) {
			for ( int last = list.length - 1; last >= 0; last-- ) {
				for ( int index = 0; index < last; index++ ) {
					if ( list[ index ].compareTo( list[ index + 1 ] ) > 0 ) {
						T temp = list[ index ];
						list[ index ] = list[ index + 1 ];
						list[ index + 1 ] = temp;
					}
				}
			}
Fe		}
		
1		public static void main( String[] args ) {
			Integer[] scores = new Integer[]{ 90, 89, 86 };
2			sort( scores );
			for( int score : scores )
			    System.out.print( score + " "  );
3			System.out.println();

			String[] words = new String[]{ "carrot", "banana", "apple" };
4			sort( words );
			for( String word : words )
			    System.out.print( word + " "  );

5		}
	}








 
실행 순서