코드업 기초 100제 (자바): 1028-1046
모든 문제는 코드업에서 참고했습니다.
기초-데이터형
1028 : 정수 1개 입력받아 그대로 출력2
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long input = scanner.nextLong();
System.out.println(input);
scanner.close();
}
}
1029 : 실수 1개 입력받아 그대로 출력2
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double input = scanner.nextDouble();
System.out.printf("%.11f", input);
scanner.close();
}
}
1030 : 정수 1개 입력받아 그대로 출력3
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long input = scanner.nextLong();
System.out.println(input);
scanner.close();
}
}
기초-출력변환
1031 : 10진 정수 1개 입력받아 8진수로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
System.out.printf("%o",input);
scanner.close();
}
}
or
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
String octalNum = Integer.toOctalString(input);
System.out.println(octalNum);
scanner.close();
}
}
1032 : 10진 정수 입력받아 16진수로 출력1
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
System.out.printf("%x",input);
scanner.close();
}
}
or
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
String hexNum = Integer.toHexString(input);
System.out.println(hexNum);
scanner.close();
}
}
1032 : 10진 정수 입력받아 16진수로 출력2
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
System.out.printf("%X",input);
scanner.close();
}
}
or
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
String hexNum = Integer.toHexString(input).toUpperCase();
System.out.println(hexNum);
scanner.close();
}
}
1033 : 10진 정수 입력받아 16진수로 출력2
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
String hexNum = Integer.toHexString(input).toUpperCase();
System.out.println(hexNum);
scanner.close();
}
}
or
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
String hexNum = String.format("%X", input);
System.out.println(hexNum);
scanner.close();
}
}
1034 : 8진 정수 1개 입력받아 10진수로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
int inputDecimal = Integer.parseInt(input, 8);
System.out.println(inputDecimal);
scanner.close();
}
}
1035 : 16진 정수 1개 입력받아 8진수로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String inputHex = scanner.next();
int inputDecimal = Integer.parseInt(inputHex, 16);
String inputOctal = Integer.toOctalString(inputDecimal);
System.out.println(inputOctal);
scanner.close();
}
}
or
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int inputDecimal = scanner.nextInt(16);
String inputOctal = Integer.toOctalString(inputDecimal);
System.out.println(inputOctal);
scanner.close();
}
}
1036 : 영문자 1개 입력받아 10진수로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char input = scanner.next().charAt(0);
System.out.println((int)input);
scanner.close();
}
}
1037 : 정수 입력받아 아스키 문자로 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
System.out.println((char)input);
scanner.close();
}
}
기초-산술연산
1038 : 정수 2개 입력받아 합 출력1
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] inputArray = input.split(" ");
int inputFirst = Integer.parseInt(inputArray[0]);
int inputSecond = Integer.parseInt(inputArray[1]);
long sum = (long)inputFirst + inputSecond;
System.out.println(sum);
scanner.close();
}
}
1039 : 정수 2개 입력받아 합 출력2
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] inputArray = input.split(" ");
long inputFirst = Long.parseLong(inputArray[0]);
long inputSecond = Long.parseLong(inputArray[1]);
long sum = inputFirst + inputSecond;
System.out.println(sum);
scanner.close();
}
}
1040 : 정수 1개 입력받아 부호 바꿔 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input = scanner.nextInt();
System.out.println((-1)*input);
scanner.close();
}
}
1041 : 문자 1개 입력받아 다음 문자 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char input = scanner.next().charAt(0);
char nextChar = (char)(input+1);
System.out.println(nextChar);
scanner.close();
}
}
1042 : 정수 2개 입력받아 나눈 몫 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] inputArray = input.split(" ");
int inputFirst = Integer.parseInt(inputArray[0]);
int inputSecond = Integer.parseInt(inputArray[1]);
System.out.println(inputFirst/inputSecond);
scanner.close();
}
}
1043 : 정수 2개 입력받아 나눈 나머지 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] inputArray = input.split(" ");
int inputFirst = Integer.parseInt(inputArray[0]);
int inputSecond = Integer.parseInt(inputArray[1]);
System.out.println(inputFirst%inputSecond);
scanner.close();
}
}
1044 : 정수 1개 입력받아 1 더해 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long input = scanner.nextLong();
System.out.println(input+1);
scanner.close();
}
}
1045 : 정수 2개 입력받아 자동 계산
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] inputArray = scanner.nextLine().split(" ");
int inputFirst = Integer.parseInt(inputArray[0]);
int inputSecond = Integer.parseInt(inputArray[1]);
long sum = (long)inputFirst + inputSecond;
int diff = inputFirst - inputSecond;
long product = (long)inputFirst * inputSecond;
int quotient = inputFirst/inputSecond;
int remainder = inputFirst % inputSecond;
double division = (double)inputFirst/inputSecond;
System.out.printf("%d\n%d\n%d\n%d\n%d\n%.2f\n", sum, diff, product, quotient, remainder, division);
scanner.close();
}
}
1046 : 정수 3개 입력받아 합과 평균 출력
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] inputArray = scanner.nextLine().split(" ");
int inputFirst = Integer.parseInt(inputArray[0]);
int inputSecond = Integer.parseInt(inputArray[1]);
int inputThird = Integer.parseInt(inputArray[2]);
long sum = (long)inputFirst + inputSecond + inputThird;
double avg = sum/3;
System.out.printf("%d\n%.1f\n", sum, avg);
scanner.close();
}
}
Leave a comment