내가 생각했을때 문제에서 원하는부분
There are three lines of input.
Each line contains a non-negative integer less than 10.
The first line contains the number of small treats, S, the second line contains the number of medium treats, M, and the third line contains the number of large treats, L, that Barley receives in a day.
If Barley’s happiness score is 10 or greater, output happy.
Otherwise, output sad.
내가 이 문제를 보고 생각해본 부분
BufferedReader를 사용하여 입력을 읽는다.
br.readLine() 메서드를 통해 각 줄의 입력을 읽고, Integer.parseInt()를 사용하여 문자열을 정수로 변환하여 각각 S, M, L에 저장한다.
여기서 S는 작은 간식의 개수, M은 중간 간식의 개수, L은 큰 간식의 개수이다.
행복 점수 계산:
주어진 공식을 사용하여 행복 점수를 계산한다.
작은 간식은 1점, 중간 간식은 2점, 큰 간식은 3점으로 계산된다.
결과 출력
계산된 행복 점수가 10 이상이면 "happy"를 출력하고, 그렇지 않으면 "sad"를 출력한다.
코드로 구현
package baekjoon.baekjoon_26;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// 백준 19602번 문제
public class Main916 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// 입력 받기
int S = Integer.parseInt(br.readLine());
int M = Integer.parseInt(br.readLine());
int L = Integer.parseInt(br.readLine());
// 행복 점수 계산
int happinessScore = (1 * S) + (2 * M) + (3 * L);
// 결과 출력
if(happinessScore >= 10) {
System.out.println("happy");
} else {
System.out.println("sad");
}
br.close();
}
}
코드와 설명이 부족할수 있습니다. 코드를 보시고 문제가 있거나 코드 개선이 필요한 부분이 있다면 댓글로 말해주시면 감사한 마음으로 참고해 코드를 수정 하겠습니다.