17
정답: 10001
조건
재귀함수를 사용하시오
package _36;
import java.util.Scanner;
public class Main{
public static void decTobin(int N){
if (N/2 == 0){ //탈출조건 2로 계속 나누다가 몫이 0이되면 탈출
System.out.print(N);
return;
}
decToBin(N/2);
System.out.print(N%2); //17 1 8 0 4 0 2 0 +탈출조건 1
//즉 10001이 된다
}
public static void main(String[] args){
Scanner scan = new Scanner(Sysyem.in);
int input = scan.nextInt(); //정수 입력
decTobin(input); //재귀함수
}
}
'JAVA' 카테고리의 다른 글
치킨쿠폰 (0) | 2021.05.14 |
---|---|
입력된 단지의 수와 각 단지의 세대수를 출력하시오 (0) | 2021.05.13 |
숫자 추출 재귀 (0) | 2021.05.11 |
피보나치수열 재귀 (0) | 2021.05.11 |
입력된 두 수까지의 합을 구하시오 (0) | 2021.05.10 |