25304번 - 영수증
import java.util.*;
public class Main {
public static void main (String args[]){
int X ; // 총금액
int N ; // 물건의 종류의 수
int a = 0; // 물건의 가격
int b = 0 ; // 물건의 갯수
int total = 0; //계산한 값
Scanner sc = new Scanner (System.in);
System.out.print("영수증에 쓰여진 총 금액을 입력하세요:");
X = sc.nextInt();
System.out.print("물건의 종류의 수를 입력하세요");
N =sc.nextInt();
for(int i=1; i<=N; i++) {
System.out.print("물건의 가격을 입력하세요 :");
a = sc.nextInt();
if(a <1 || a > 1000000000) {
System.out.println("가격의 범위는 1원 이상 1,000,000,000원 이하입니다");
}
System.out.print("물건의 갯수를 입력하세요 :");
b = sc.nextInt();
total += a * b;
if(b<1 || b>100) {
System.out.println("물건의 갯수는 1개 이상 100개 이하입니다.");
System.out.println("total=" + total);
System.out.println("X=" + X);
if(X == (total)) {
System.out.println("YES");
else {
System.out.println("NO");
여기서 어떻게 바꿔야 출력초과가 안날까요?
총 금액을 입력하세요 등등.. 의 불필요한 print문들을 싹 날리면 됩니다.
예제 출력에는 오로지 "Yes" 또는 "No" 한 줄만이 있습니다. 따라서, 질문자님의 프로그램이 생성하는 출력도 오로지 "Yes" 또는 "No" 뿐이어야 합니다. 사용자에게 무언가를 입력하라고 요구하는 안내 메시지도 출력에 포함되며, 정답 출력과 달라지게 되므로 틀리게 됩니다.
감사합니다!
댓글을 작성하려면 로그인해야 합니다.
helloguys 2년 전
import java.util.*;
public class Main {
public static void main (String args[]){
int X ; // 총금액
int N ; // 물건의 종류의 수
int a = 0; // 물건의 가격
int b = 0 ; // 물건의 갯수
int total = 0; //계산한 값
Scanner sc = new Scanner (System.in);
System.out.print("영수증에 쓰여진 총 금액을 입력하세요:");
X = sc.nextInt();
System.out.print("물건의 종류의 수를 입력하세요");
N =sc.nextInt();
for(int i=1; i<=N; i++) {
System.out.print("물건의 가격을 입력하세요 :");
a = sc.nextInt();
if(a <1 || a > 1000000000) {
System.out.println("가격의 범위는 1원 이상 1,000,000,000원 이하입니다");
}
System.out.print("물건의 갯수를 입력하세요 :");
b = sc.nextInt();
total += a * b;
if(b<1 || b>100) {
System.out.println("물건의 갯수는 1개 이상 100개 이하입니다.");
}
}
System.out.println("total=" + total);
System.out.println("X=" + X);
if(X == (total)) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
여기서 어떻게 바꿔야 출력초과가 안날까요?