JAVA

[프로그래머스] 덧셈식 출력하기

코린이도이 2023. 11. 7. 14:41

- 문제

두 정수 ab가 주어질 때 다음과 같은 형태의 계산식을 출력하는 코드를 작성해 보세요.

 

- 답

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

        System.out.println(a + " + " + b + " = "+ (a + b));
    }
}

 

- 해설

+를 이용하여 문자열 합칠 수 있음