JAVA2010. 9. 9. 13:58

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
Posted by 달빛낙엽
JAVA2010. 9. 8. 17:57

import java.io.*;
public class SysInfo {
public static void main(String[] args) throws Exception
    {
        Process proc = null;
        BufferedReader procStdOut = null;
        try
        {
            // windows 폴더내의 systeminfo 파일을 읽어온다.
            proc = Runtime.getRuntime().exec("C:\\WINDOWS\\system32\\systeminfo");
            procStdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            String line;
            while (true)
            {
                line = procStdOut.readLine();
                if (line == null) break;

                System.out.println(line);
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            if (proc != null)
            proc.destroy(); // process를 kill시킨다.
            if (procStdOut != null)
            procStdOut.close();
        }
    }
} 

'JAVA' 카테고리의 다른 글

2진수 10진수로 변환  (0) 2010.09.09
10진수 2진수,8진수 변환  (0) 2010.09.09
JAVA 시스템 환경읽어오기  (0) 2010.09.08
JAVA Generic 예제  (0) 2010.08.12
JAVA 향상된 For문  (0) 2010.08.12
Posted by 달빛낙엽
JAVA2010. 9. 8. 17:56

import java.util.Enumeration;
import java.util.Properties;


public class GetRuntimeInfo {
    private void getRuntimeInformation(){
        Properties properties = null;
       
        try{
            properties = System.getProperties();
        }catch(Exception e){
            e.printStackTrace();
        }
       
        Enumeration en = properties.propertyNames();
        while(en.hasMoreElements()){
            String s = (String)en.nextElement();
            String stringValue = properties.getProperty(s);
            System.out.println(s + " : " + stringValue);           
        }
    }
   
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new GetRuntimeInfo().getRuntimeInformation();
    }
} 

'JAVA' 카테고리의 다른 글

10진수 2진수,8진수 변환  (0) 2010.09.09
java systeminfo파일로 정보읽기  (0) 2010.09.08
JAVA Generic 예제  (0) 2010.08.12
JAVA 향상된 For문  (0) 2010.08.12
JAVA Generic  (0) 2010.08.12
Posted by 달빛낙엽