본문 바로가기

오답노트/백준알고리즘(Java&Python)

[백준 알고리즘 : 10869] 사칙연산

Java

 

 

import java.util.Scanner;

class Main {
    public static void main (String [] args ){
          Scanner scan = new Scanner(System.in);
          int A = scan.nextInt();
          int B = scan.nextInt();

          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);
      }
}

 

 

  • Scanner : 자바에서 가장 대표적인 숫자형성함수 

 

scanner 함수 설명 : https://st-lab.tistory.com/92

 

 

 

Python

 

 

a, b = input().split()
a, b = int(a), int(b)

print(a+b)
print(a-b)
print(a*b)
print(a//b)
print(a%b)

 

 

  • 파이썬은 java와 다르게 ; 가 필요없음
  • 파이썬은 한 줄에 변수 N 개 사용 가능
  • 자바는 /, 파이썬은 //

 

split 함수 설명 : https://study-all-night.tistory.com/104

한줄에 변수 2개 설정 : https://uhhyunjoo.tistory.com/20