제네릭 리스트에 점수 및 단어를 저장하고 출력하는 문제입니다 이를 해결하는 다음 프로그램에 대해 빈칸을 채우세요
86 89 90 apple banana carrot
public class GenericListMain {
public static void main( String[] args ) {
GenericList<> scores =
new GenericList<>( 3 );
scores.add( 86 );
scores.add( 89 );
scores.add( 90 );
for( int i = 0; i < scores.size; i++ )
System.out.print( scores.get( i ) + " " );
System.out.println();
GenericList<> words =
new GenericList<>( 3 );
words.add( "apple" );
words.add( "banana" );
words.add( "carrot" );
for( int i = 0; i < words.size; i++ )
System.out.print( words.get( i ) + " " );
}
}
public class GenericList<> {
private [] list;
protected int size;
public GenericList( int capacity ) {
size = 0;
list = new [capacity];
}
public void add( item ) {
list[size++] = item;
}
public get( int index ) {
return ()list[index];
}
}