알고리즘 기초 - 4 (10진수를 2진수로 변환)
Algorithm/풀었던문제 2019. 12. 4. 11:0710진수를 2진수로 변환할때는 Integer클래스를 사용하면 편리하게 진수 변환을 할 수 있다.
Main.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | package Problem4; import java.util.Scanner; public class Main { public static void main(String[] args) { //10진수를 2진수로 변환하기 for(int i = 0; ; i++) { System.out.println(); System.out.println(); System.out.println("변환할 10진수를 입력하세요."); Scanner scan = new Scanner(System.in); int a = scan.nextInt(); System.out.println("내가 입력한 10진수 : "+a); int[] arr = new int[50]; arr[0] = a; //10진수를 2진수로 변환할때는 Integer클래스의 API를 활용하면 편하게 변환할 수가 있다. String a2 = Integer.toBinaryString(arr[0]); System.out.println("10진수를 2진수로 변환한 숫자 : "+a2); } } } | cs |
출력 결과
출처
https://www.youtube.com/watch?v=8Xh2Zgap9hs&list=PLVoihNyHW4xkm_KJ8_N8X7F6EQP4uSRyR&index=5
'Algorithm > 풀었던문제' 카테고리의 다른 글
알고리즘 기초 - 6 (최대 공약수 구하기) (0) | 2019.12.07 |
---|---|
알고리즘 기초 - 5 (대, 소문자 변환) (0) | 2019.12.04 |
알고리즘 기초 - 3 (최빈수 출력) (0) | 2019.12.03 |
알고리즘 기초 - 2 (파보나치 수열 출력) (0) | 2019.12.03 |
알고리즘 기초 - 1 (학생이름 저장 및 검색) (0) | 2019.11.30 |