# 1031 : 10진수 → 8진수
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
String octal = Integer.toOctalString(num); // 10진수 -> 8진수
System.out.println(octal);
sc.close();
}
}
# 1032 : 10진수 → 16진수
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
String hex = Integer.toHexString(num); // 10진수 -> 16진수
System.out.println(hex);
sc.close();
}
}
# 1033 : 10진수 → 16진수(대문자로)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
String hex = Integer.toHexString(num); // 10진수 -> 16진수
System.out.println(hex.toUpperCase());
sc.close();
}
}
# 1034 : 8진수 → 10진수
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String octal = sc.next();
System.out.println(Integer.parseInt(octal,8)); // 8진수 -> 10진수
sc.close();
}
}
# 1035 : 16진수 → 8진수
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String hex = sc.next();
int num = Integer.parseInt(hex, 16); // 16진수 -> 10진수
String octal = Integer.toOctalString(num); // 10진수 -> 8진수
System.out.println(octal);
sc.close();
}
}
# 1036 : 문자 → 정수
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char ch = sc.next().charAt(0);
int num = (int)ch; // 문자 -> 숫자
System.out.println(num);
sc.close();
}
}
# 1037 : 정수 → 문자
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
char ch = (char)num; // 숫자 -> 문자
System.out.println(ch);
}
}
CodeUp
☆ 파이썬 다운로드 : 파이썬3 ☆ 무료 C언어 IDE : Code::blocks DEV C++ ☆ 추천 온라인 IDE : C C++11 Python3 Java ☆ 채점 가능 언어 : C, C++, JAVA, Python 3.5 ★ C++로 제출시 void main()을 사용하면
codeup.kr
'CodeUp > Java' 카테고리의 다른 글
[CodeUp] 1047-1048 (Java) (0) | 2022.10.29 |
---|---|
[CodeUp] 1038-1046 (Java) (0) | 2022.10.28 |
[CodeUp] 1028-1030 (Java) (0) | 2022.10.26 |
[CodeUp] 1010-1027 (Java) (0) | 2022.10.25 |
[CodeUp] 1001-1008 (Java) (0) | 2022.10.24 |