Network disconnection
Description
데이터를 중간에 추가하려면 먼저 데이터를 추가할 빈 공간을 확보해야 합니다. index번째 위치에 빈 공간을 확보하려면, 원래 index번째에 있던 데이터와, 그 뒤에 있던 데이터를 뒤로 밀어줘야합니다.
for문을 이용해, 끝부터 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
class ArrayList {
private int size = 0;
private Object[] elementData = new Object[50];
public boolean addLast(Object e)
{
elementData[size++] = e;
return true;
}
public boolean add(int index, Object element)
{
//끝부터 index번째까지의 데이터를 한칸씩 뒤로 이동시키세요.
for(int i=size-1; ; i--)
{
elementData[ ] = elementData[ ];
}
return true;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
public class MainRunner
{
public static void main(String[] args)
{
ArrayList arraylist = new ArrayList();
arraylist.addLast(3);
arraylist.addLast(5);
arraylist.add(1, 4);
System.out.println("제출하세요.");
}
}
Result
Stop
Result of [Run] or [Submit] will be displayed here