냠냠냠
java) 십진수 정수를 받아 이진수로 표현하기(재귀적 함수 이용) 본문
문제) 십진수 정수를 받아 이진수로 출력하기. (메소드를 재귀의 형태로 정의할 것)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
public class MethodJustice {
public static void main(String[] args) {
trans(11);
}
public static int trans(int n) {
if(n > 0) {
int binary = n % 2; // 1, 1, 0, 1
n /= 2; // 5, 2, 1, 0
trans(n); // trans(5), trans(2), trans(1), trans(0)
System.out.print(binary);
}
return 0;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'언어 > JAVA' 카테고리의 다른 글
java) String 클래스 메소드 정리 (0) | 2019.12.08 |
---|---|
java ) 자바 용어 정리 (0) | 2019.12.07 |
java) 재귀적 함수 기본 모델 (0) | 2019.12.02 |
java) 100 이하 소수(Prime Number) 출력하기 (0) | 2019.12.02 |
java) 두 자리수 덧셈 합 99 만족하는 수 조합 찾기 (0) | 2019.11.29 |
Comments