[Javaアルゴリズム]7-2.バイナリしゅつりょく
4417 ワード
🌼 Problem

🍔 Solution 1
import java.util.Scanner;
public class _72_이진수출력 {
// 방법 1
public static void Solution(int n){
String answer = "";
if(n==0){
return;
}else{
Solution(n/2);
answer += n%2;
}
System.out.print(answer);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
Solution(input);
}
}
[結果]
🍪 講師ソリューション
import java.util.Scanner;
public class _72_이진수출력 {
// 방법 2 : 강사
public static void Solution(int n){
if(n==0) return;
else{
Solution(n/2);
System.out.print(n%2+ " ");
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
Solution(input);
}
}
[結果]
Reference
この問題について([Javaアルゴリズム]7-2.バイナリしゅつりょく), 我々は、より多くの情報をここで見つけました https://velog.io/@dingdoooo/Java알고리즘-7-2.-이진수-출력재귀テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol