실버 4
https://www.acmicpc.net/problem/2089
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// 2089번 -2진법
public class boj_5_2089 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int input = Integer.parseInt(br.readLine());
if (input == 0)
System.out.println(0);
else {
while (input != 1) {
sb.append(Math.abs(input % -2));
input = (int) Math.ceil((double) input / (-2));
}
sb.append(input);
System.out.println(sb.reverse());
}
}
}
십진수를 이진수로 변환하는 것처럼 풀지만 올림처리(Math.ceil)를 해주어야한다.