코드업 기초2. 입출력문 및 연산자
업데이트:
1110 전 문제들은 기초 100제 안에 포함되어있다.
[1110] 정수 그대로 출력하기
[입력] 5
[출력] 5
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.print(num);
}
}
[1111] % 출력
[입력] 35
[출력] 35%
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.print(num+"%");
}
}
[1112] 두 정수 출력
[입력] 5 7
[출력] 5 7
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num1 + " " + num2);
}
}
[1113] 바꿔서 출력하기
[입력] 1 2
[출력] 2 1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num2 + " " + num1);
}
}
[1114] 두 정수의 덧셈
[입력] 5 7
[출력] 12
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num1+num2);
}
}
[1115] 두 정수의 덧셈 (64비트)
[입력] 11111111111 22222222222
[출력] 33333333333
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long num1 = sc.nextLong();
long num2 = sc.nextLong();
System.out.print(num1+num2);
}
}
[1116] 사칙연산 계산기
[입력] 3 2
[출력]
3+2=5
3-2=1
3*2=6
3/2=1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.printf("%d+%d=%d\n", num1, num2, num1 + num2);
System.out.printf("%d-%d=%d\n", num1, num2, num1 - num2);
System.out.printf("%d*%d=%d\n", num1, num2, num1 * num2);
System.out.printf("%d/%d=%d", num1, num2, num1 / num2);
}
}
[1117] 두 실수의 곱
[입력] 1.23 4.56
[출력] 5.61
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double num1 = sc.nextDouble();
double num2 = sc.nextDouble();
System.out.printf("%.2f", num1 * num2);
}
}
[1118] 삼각형의 넓이 구하기
[입력] 5 2
[출력] 5.0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.printf("%.1f", (float)num1 * num2 / 2);
}
}
[1119] 일을 시간으로 변환
[입력] 2
[출력] 48
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
System.out.print(num1 * 24);
}
}
[1120] 세 수의 평균
[입력] 1 2 3
[출력] 2.00
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
int num3 = sc.nextInt();
System.out.printf("%.2f", (float)(num1 + num2 + num3) / 3);
}
}
[1121] 나머지 구하기
[입력] 7 5
[출력] 2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num1 % num2);
}
}
[1122] 초를 분/초로 변환
[입력] 70
[출력] 1 10
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int second = sc.nextInt();
int minute = second / 60;
second = second % 60;
System.out.print(minute + " " + second);
}
}
[1123] 섭씨 온도를 화씨 온도로 변환
[입력] 30
[출력] 86.000
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int c = sc.nextInt();
double f = (double)9 / 5 * c + 32;
System.out.printf("%.3f", f);
}
}
[1125] 8진수 16진수 변환
[입력] 10
[출력] 12 A
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.printf("%o %X", num, num);
}
}
[1131] 문자 출력하기
[입력] a
[출력] a
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);
System.out.print(ch);
}
}
[1132] 문자열 출력하기
[입력] cat
[출력] cat
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String st = sc.next();
System.out.print(st);
}
}
[1133] 공백이 있는 문자열 입출력
[입력] black sheep wall
[출력] black sheep wall
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String st = sc.nextLine();
System.out.print(st);
}
}
[1135] 관계연산자 1
[입력] 2 3
[출력] 0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
if(num1 >= num2)
System.out.print(1);
else
System.out.print(0);
}
}
[1136] 관계연산자 2
[입력] 2 3
[출력] 0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
if(num1 == num2)
System.out.print(1);
else
System.out.print(0);
}
}
[1137] 관계연산자 3
[입력] 2 3
[출력] 0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
if(num1 != num2)
System.out.print(1);
else
System.out.print(0);
}
}
[1138] 논리 연산자(NOT)
[입력] 0
[출력] 1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
System.out.print(num1 == 0 ? 1 : 0);
}
}
[1139] 논리 연산자(AND)
[입력] 1 0
[출력] 1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num1 == 1 && num2 == 1 ? 1 : 0);
}
}
[1140] 논리 연산자(OR)
[입력] 0 1
[출력] 1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num1 == 1 || num2 == 1 ? 1 : 0);
}
}
[1143] 비트 연산자(AND)
[입력] 3 5
[출력] 1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num1&num2);
}
}
[1144] 비트 연산자(OR)
[입력] 3 5
[출력] 7
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num1|num2);
}
}
[1147] 비트 연산자(«)
[입력] 3 3
[출력] 24
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int x = sc.nextInt();
System.out.print(num1 << x);
}
}
[1148] 비트 연산자(»)
[입력] 4 1
[출력] 2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int x = sc.nextInt();
System.out.print(num1 >> x);
}
}
[1149] 두 수 중 큰 수
[입력] 2 7
[출력] 7
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
System.out.print(num1 > num2 ? num1 : num2);
}
}
[1150] 세 수 중 가장 작은 수
[입력] 3 5 2
[출력] 2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
int num3 = sc.nextInt();
System.out.print(num1 > num2 ? (num2 > num3 ? num3 : num2) : (num1 > num3 ? num3 : num1)) ;
}
}
댓글남기기