Network disconnection
Description
데이터를 아무리 많이 저장해도 저장한 데이터를 불러올 수 없다면 무슨 소용일까요? n번째에 위치한 데이터를 불러오는 get 메소드를 만들어 봅시다. 다음 조건에 맞춰, get 메소드 안의 빈 칸을 채워보세요.
- get 메소드는 elementData의 원소와 같은 타입을 리턴한다.
- get 메소드는 인자 index번째의 원소를 리턴한다.
Fill type challenge HOWTO
- In the Fill type challenge, you have to fill the blank with appropriate code
- The given code except the blank cannot be edited.
- An error message will be shown in the Result area when you leave the blank empty.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class ArrayList {
private int size = 0;
private Object[] elementData = new Object[50];
// index에 위치한 데이터를 가져오는 get 함수를 완성하세요.
public get(int index)
{
return ;
}
public boolean addLast(Object e)
{
elementData[size++] = e;
return true;
}
public boolean add(int index, Object element)
{
for (int i = size - 1; i >= index; i--) {
elementData[i + 1] = elementData[i];
}
elementData[index] = element;
size++;
return true;
}
public boolean addFirst(Object element)
{
return add(0, element);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class MainRunner
{
public static void main(String[] args)
{
ArrayList arraylist = new ArrayList();
arraylist.addLast(1);
arraylist.addLast(2);
arraylist.addLast(3);
int val = (int)arraylist.get(1);
if(val != 2)
{
System.out.println("틀렸습니다. 다시 한 번 생각해보세요");
return ;
}
System.out.println("제출하세요.");
}
}
Result
Stop
Result of [Run] or [Submit] will be displayed here