-
문자열로 된 이진수를 입력받아, 아래의 규칙에 따라 0으로 만드는 횟수를 출력하는 프로그램
- 짝수일 경우 나누기 2를 한다 (8 -> 4)
- 홀수일 경우 빼기 1을 한다 (7 -> 6)
- 이진수는 0으로 시작할 수도 있다 (ex 011000)
-
ex) "011100" 입력
- 십진수 28
-
- 28 / 2 -> 14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.jupiter.api.Assertions.assertEquals; | |
import org.junit.Test; | |
public class DynamicArrayTest { | |
@Test | |
public void init() { | |
DynamicArray<Integer> da = new DynamicArray<>(); | |
assertEquals(0, da.size()); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface DynamicArrayADT<E> { | |
int size(); | |
void set(int index, E value); | |
E get(int index); | |
E remove(int index); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DynamicArray<E> { | |
private static final int DEFAULT_SIZE = 10; | |
private int size; | |
private Object[] arr; | |
public DynamicArray() { | |
this.size = 0; | |
this.arr = new Object[DEFAULT_SIZE]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body onload = main()> | |
<script> |