Archives
Recent Posts
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
관리 메뉴

개발도생's Blog

[백준][Java] 6825_Body Mass Index 본문

BaekJoon

[백준][Java] 6825_Body Mass Index

개발도생 2023. 3. 28. 11:17

[백준] 6825_Body Mass Index 문제

 

6825번: Body Mass Index

The Body Mass Index (BMI) is one of the calculations used by doctors to assess an adult’s health. The doctor measures the patient’s height (in metres) and weight (in kilograms), then calculates the BMI using the formula BMI = weight/(height × height).

www.acmicpc.net


6825, Body Mass Index 문제


BMI 수치를 확인해서 출력 값을 다르게 하는 문제이다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		double weight = Double.parseDouble(br.readLine());
		double height = Double.parseDouble(br.readLine());
		                
		double BMI = weight / (height * height);
		
		if(BMI < 18.5) {
			System.out.println("Underweight");
		} else if(BMI <= 25 && BMI >= 18.5) {
			System.out.println("Normal weight");
		} else if(BMI > 25){
			System.out.println("Overweight");
		}
	}
}

먼저 사용자 입력 값을 줄을 띄어서 두 번 입력해야 했다.

 

사용자 입력은 Bufferedreader Class를 활용해서 객체를 만들어 사용했다. 

 

[Java][Class] Bufferedreader

코딩 테스트 문제들을 풀다가 우연히 알게 된 Bufferedreader 객에 대해서 공부해봤다. Bufferedreader Class는, 이름과 같이 버퍼를 사용하는 클래스다. 일반적으로 알고 있던 Scanner Class는 사용자가 값을

nan-o-nuel-do.tistory.com

Bufferedreader 객체를 통해 입력 값을 받아서 실수 타입의 자료형 변수에 

 

Double.parseDouble() Method를 통해 형 변환 시켜 저장해주었다.

 

동일한 실수 타입의 BMI 변수에 각각(weight, height)의 변수에 저장된 값으로 연산을 하고 저장해주었다.

 

예시에 나와 있는 조건을 조건문으로 만들어 BMI에 저장된 값으로 비교해주면 된다.


입력해야 되는 값
출력 값
입력해야 되는 값
출력 값


위와 같은 코드로 제출했을 때,   

맞았습니다!!

'BaekJoon' 카테고리의 다른 글

[백준][Java] 9772_Quadrants  (4) 2023.04.11
[백준][Java] 6887_Squares  (0) 2023.03.31
[백준][Java] 5358_Football Team  (0) 2023.03.20
[백준][Java] 5357_Dedupe  (0) 2023.03.19
[백준][Java] 5300_Fill the Rowboats!  (0) 2023.03.15
Comments