코딩 테스트/JAVA
프로그래머스 - (lv.0) 덧셈식 출력하기
Helmi
2023. 5. 17. 13:45
또 다시 간단한 문제
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));
}
}
이렇게 해도 통과는 되나 제한 사항을 만족시키기 위해 if문을 추가해 주었다.
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();
if(a>=1 && b>=1 && a<=100 && b<=100)
System.out.println(a + " + " + b + " = " + (a+b));
}
}