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 36 37 38 39 40 | import java.util.*; public class Test { public static void main (String args[]) { java.util.Scanner in = new Scanner(System.in); ArrayList binary = new ArrayList(); // 2진수 배열저장 ArrayList octal = new ArrayList(); // 8진수 배열저장 int input = in.nextInt(); // 입력받은 숫자 int input2 = input; // 입력받은 숫자 System.out.print( "숫자를 입력하세요. : " ); while (input != 0 ){ binary.add(input % 2 ); input = input / 2 ; } while (input2 != 0 ){ octal.add(input2 % 8 ); input2 = input2 / 8 ; } System.out.print( "2진수 : " ); for ( int a = binary.size(); a > 0 ; a --){ System.out.print(binary.get(a- 1 )); } System.out.println( "" ); // 줄바꿈 System.out.print( "8진수 : " ); for ( int a = octal.size(); a > 0 ; a --){ System.out.print(octal.get(a- 1 )); } } } |
'JAVA' 카테고리의 다른 글
예약어 new (0) | 2011.08.01 |
---|---|
2진수 10진수로 변환 (0) | 2010.09.09 |
java systeminfo파일로 정보읽기 (0) | 2010.09.08 |
JAVA 시스템 환경읽어오기 (0) | 2010.09.08 |
JAVA Generic 예제 (0) | 2010.08.12 |