백준 도전기(사칙연산)

주재일·2021년 4월 25일

1000번 문제

A 와 B 를 입력시 A+B 의 값을 출력하시오.



public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println(a + b);
		
		sc.close();
	}
}

번외,

A+B, A-B, A*B 도 같은 방식으로 출력 값만 바꿔주면 된다.


A / B 는 정수 int 를 Double 로 바꿔주어 계산하면 된다.

참고자료 자료정수형

double a = sc.nextDouble();
double b = sc.nextDouble();

마지막 5개의 연산문제도 비슷하게 클리어

System.out.println(a + b);
System.out.println(a - b);
System.out.println(a * b);
System.out.println(a / b);
System.out.println(a % b);
profile
늦게 시작했으니 저는 늦둥이인가요?

0개의 댓글