제니노트

[기초-출력변환] 1031-1037 [자바] 본문

코딩테스트/코드업

[기초-출력변환] 1031-1037 [자바]

yangjennie 2023. 1. 17. 21:08
반응형

1031

10진수를 입력받아 8진수(octal)로 출력해보자.

 

 

//1031
public class Main{ 
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(br.readLine());
        System.out.printf("%o", a);

    }
}

 

 

1032

10진수를 입력받아 16진수(hexadecimal)로 출력해보자.

//1032

public class Main{ 

public static void main(String args[]) throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.***in***));

int a = Integer.*parseInt*(br.readLine());

System.***out***.printf("%x", a);

}

}

 

 

1033

10진수를 입력받아 16진수(hexadecimal)로 출력해보자.

 

 

import java.io.*;
import java.util.*;

//1033
public class Main{ 
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(br.readLine());
        System.out.print(Integer.toHexString(a).toUpperCase());

    }
}

 

 

1034

8진수로 입력된 정수 1개를 10진수로 바꾸어 출력해보자.



import java.io.*;
import java.util.*;

//1034
public class Main{ 
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(br.readLine(),8);
        System.out.printf("%d", a);
    }
}

 

 

1035

16진수로 입력된 정수 1개를 8진수로 바꾸어 출력해보자.

 

 

import java.io.*;
import java.util.*;

//1035
public class Main{ 
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(br.readLine(),16);
        System.out.printf("%o", a);
    }
}

 

 

1036

영문자 1개를 입력받아 아스키 코드표의 10진수 값으로 출력해보자.

 

 

import java.io.*;
import java.util.*;

//1036
public class Main{ 
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char a = br.readLine().charAt(0);
        int ascii = (int)a;
        System.out.printf("%d", ascii);

    }
}

 

 

1037

10진 정수 1개를 입력받아 아스키 문자로 출력해보자.
단, 0 ~ 255 범위의 정수만 입력된다.



import java.io.*;
import java.util.*;

//1037
public class Main{ 
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(br.readLine());
        char b = (char)a;
        System.out.printf("%6c", b);


    }
}



반응형
Comments