1. 문제
2. 제출 답안
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));
}
}
문자 쓸 때 따옴표와 + 잘 써 주기
3. 다른 풀이
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.printf("%d + %d = %d",a,b,a+b);
}
}
printf : 서식이 있는 출력
%d : 정수
%f : 실수
%c : 문자
%s : 문자열
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;
System.out.println(a + " + " + b + " = " + sum);
}
}
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Lv.0 문자열 돌리기(Java) (0) | 2023.10.18 |
---|---|
[프로그래머스] Lv.0 문자열 붙여서 출력하기(Java) (0) | 2023.10.18 |
[프로그래머스] Lv.0 특수문자 출력하기(Java) (0) | 2023.10.17 |
[프로그래머스] Lv.0 대소문자 바꿔서 출력하기(Java) (0) | 2023.10.17 |
[프로그래머스] Lv.0 문자열 반복해서 출력하기(Java) (0) | 2023.10.17 |