본문 바로가기
Algorithm/Programmers

프로그래머스 ) 덧셈식 출력하기 [JAVA/자바] - 오늘의 TIL

by 그리밍밍 2023. 7. 7.

https://school.programmers.co.kr/learn/courses/30/lessons/181947

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr


👇소스 코드

import java.util.Scanner;

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

        System.out.printf("%d + %d = %d", a,b,sum);
    }
}

🐣코드 설명

✔️ 두 정수 a,b를 Scanner를 이용하여 받아온 후 출력해준다.

✔️ int형 데이터를 나타내기 위해서 '%d'라는 서식 지정자를 사용하였다. (이 때는 printf로 써줘야한다! )

728x90