자바 1000제
1주
강남
입문
x 1
# 비만도 측정
대학생이 되어 열심히 다이어트중인 나몸짱(20) 학생. 열심히 운동도 하고 식단 조절도 하고있는데.. 과연 잘 하고 있는 걸까?
## 문제
입력받은 키(m)와 몸무게(kg)를 토대로 BMI 지수를 계산하여 비만도를 측정 프로그램을 만들어 주세요.
## 요구사항
+ 비만도는 아래의 네 가지 단계로 구분 할 것.
+ 저체중(18.5미만), 정상(18.5이상 ~ 25미만), 과체중(25이상~30미만), 비만(30이상)
## BMI 지수란?
체질량 지수(體質量指數, Body Mass Index, BMI)는 인간의 비만도를 나타내는 지수로, 체중과 키의 관계로 계산된다. 키가 t 미터, 체중이 w 킬로그램일 때, BMI는 다음과 같다. - 위키피디아 -
+ BMI = w / t^2
## 뼈대코드
```
import java.util.Scanner;
class BMICalculator {
public static double calculateBMI(double weight, double tall) {
// 해당 메소드를 구현하세요.
return 0;
}
public static void printBMIClassification(double bmi) {
// 해당 메소드를 구현하세요.
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double weight = input.nextDouble();
double tall = input.nextDouble();
// BMI 지수 계산
double bmi = calculateBMI(weight, tall);
// BMI 지수를 입력하여 비만도 결과 출력
printBMIClassification(bmi);
}
}
```
## 입력 예
```
// 몸무게(kg) 키(m) 순 입력
74.5 1.76
```
## 출력 예
```
BMI: 24.05
정상 입니다.
```
```
import java.util.Scanner;
class BMICalculator {
public static double calculateBMI(double weight, double tall) {
double bmi = weight / (tall*tall);
// 해당 메소드를 구현하세요.
//저체중(18.5미만), 정상(18.5이상 ~ 25미만), 과체중(25이상~30미만), 비만(30이상)
if (bmi<18.5) {
System.out.println("저체중");
}
else if (bmi<25) {
System.out.println("정상");
}
else if (bmi<30) {
System.out.println("체중");
}
else {
System.out.println("비만");
}
return bmi;
}
public static void printBMIClassification(double bmi) {
// 해당 메소드를 구현하세요.
}
public static void main(String[] args) {
System.out.println("몸무게(kg)와 키(m)를 입력하세요.");
Scanner input = new Scanner(System.in);
double weight = input.nextDouble();
double tall = input.nextDouble();
// BMI 지수 계산
double bmi = calculateBMI(weight, tall);
// BMI 지수를 입력하여 비만도 결과 출력
System.out.println(bmi);
}
}
```
import java.util.Scanner;
public class seo_java {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("몸무게 입력하세요(kg) : ");
float weight = input.nextFloat();
System.out.print("키 입력하세요(m) : ");
float high = input.nextFloat();
float BMI = weight / (high * high);
System.out.println("BMI : "+ BMI);
if(BMI >= 30) System.out.println("비만 입니다.");
else if (BMI >= 25) System.out.println("과체중 입니다.");
else if (BMI >= 18.5) System.out.println("정상 입니다.");
else System.out.println("저체중 입니다.");
}
}
class BMICalculator {
public static double calculateBMI(double weight, double tall) {
return weight / (tall * tall);
}
public static void printBMIClassification(double bmi) {
if(bmi > 30) {
System.out.printf("BMI: %.2f\n%s", bmi, "비만입니다.");
}else if (bmi < 30 && bmi >= 25) {
System.out.printf("BMI: %.2f\n%s", bmi, "과체중입니다.");
}else if (bmi < 25 && bmi >= 18.5) {
System.out.printf("BMI: %.2f\n%s", bmi, "정상입니다.");
}else if (bmi < 18.5) {
System.out.printf("BMI: %.2f\n%s", bmi, "저체중입니다.");
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double weight = input.nextDouble();
double tall = input.nextDouble();
// BMI 지수 계산
double bmi = calculateBMI(weight, tall);
// BMI 지수를 입력하여 비만도 결과 출력
printBMIClassification(bmi);
}
}
import java.util.Scanner;
class BMICalculator {
public static double calculateBMI(double weight, double tall) {
// 해당 메소드를 구현하세요.
double bmi=weight/(tall*tall);
return bmi;
}
public static void printBMIClassification(double bmi) {
// 해당 메소드를 구현하세요.
String suchi="";
if(bmi>=30) {
suchi="비만";
}
else if(bmi<30 && bmi>=25) {
suchi="과체중";
}
else if(bmi<25 && bmi>=18.5) {
suchi="정상";
}
else if(bmi<18.5) {
suchi="저체중";
}
System.out.println(suchi);
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("몸무게를 넣어주세요:");
double weight = input.nextDouble();
System.out.print("키를 넣어주세요:");
double tall = input.nextDouble();
// BMI 지수 계산
double bmi = calculateBMI(weight, tall);
// BMI 지수를 입력하여 비만도 결과 출력
printBMIClassification(bmi);
}
}
package Practice_Ex;
import java.util.Scanner;
public class Ex_4 {
public static double calculateBMI(double weight, double tall) {
double bmi = (int)(weight/(tall*tall)*100)/100.0;
System.out.println("bmi: " + bmi);
return bmi;
}
public static void printBMIClassification(double bmi) {
if(bmi<18.5) {
System.out.println("저체중");
}else if(bmi<25){
System.out.println("정상");
}else if(bmi<30) {
System.out.println("과체중");
}else {
System.out.println("비만");
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("몸무게를 입력하세요 >> ");
double weight = input.nextDouble();
System.out.print("키(m)를 입력하세요 >> ");
double tall = input.nextDouble();
// BMI 지수 계산
double bmi = calculateBMI(weight, tall);
// BMI 지수를 입력하여 비만도 결과 출력
printBMIClassification(bmi);
input.close();
}
}
import java.util.Scanner;
//BMI = w / t^2
public class example_비만도측정 {
public static double calculateBMI(double weight, double tall) {
// 해당 메소드를 구현하세요.
double bmi = weight/(tall*tall) ;
System.out.printf("BMI: %.2f\n",bmi);
return bmi;
}
public static void printBMIClassification(double bmi) {
// 해당 메소드를 구현하세요.
if(bmi<18.5)
System.out.println("저체중 입니다.");
else if(bmi>=18.5 && bmi<25)
System.out.println("정상 입니다.");
else if(bmi>=25 && bmi<30)
System.out.println("과체중 입니다.");
else if(bmi>=30)
System.out.println("비만 입니다.");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double weight = input.nextDouble();
double tall = input.nextDouble();
// BMI 지수 계산
double bmi = calculateBMI(weight, tall);
// BMI 지수를 입력하여 비만도 결과 출력
printBMIClassification(bmi);
}
}
package Chap04;
import java.util.Scanner;
class BMI {
public static double calculateBMI(double weight, double tall) {
double bmi = weight / (tall * tall) * 10000;
return 0;
}
public static void printBMIClassification(double bmi) {
if(bmi > 30) {
System.out.println("비만입니다.");
} else if(bmi > 25) {
System.out.println("과체중입니다.");
} else if(bmi > 18.5) {
System.out.println("정상입니다.");
} else if(bmi <= 18.5) {
System.out.println("저체중입니다.");
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("몸무게를 입력하세요.");
double weight = input.nextDouble();
System.out.println("키를 입력하세요.");
double tall = input.nextDouble();
// BMI 지수 계산
double bmi = calculateBMI(weight, tall);
// BMI 지수를 입력하여 비만도 결과 출력
System.out.println("bmi 결과 : "+bmi);
printBMIClassification(bmi);
}
}
package 예제;
import java.util.Scanner;
class Person {
double height;
int weight;
double bmi;
static final double NORMAL = 18.5; //18.5 넘어야 정상
static final double OVERWEIGHT = 25; //25보다 넘어야 과체중
static final double FAT = 30; //30 넘어야 비만
Person() {
}
Person(int height, int weight) {
this.height = height*100/10000.0; //m단위로 변환
this.weight = weight;
bmi = (double)weight / Math.pow(height, 2)*10000;
}
void obesity() {
// 저체중 기준 몸무게
double underweight = Math.pow(height, 2) * NORMAL;
// 정상 기준 몸무게
double normal_weight = Math.pow(height, 2) * OVERWEIGHT;
// 과체중 기준 몸무게
double overweight = Math.pow(height, 2) * FAT;
if (bmi < NORMAL) {
System.out.println("저체중입니다");
System.out.printf("정상이 되려면 %.1fkg 더 쪄야 합니다", weight - underweight);
} else if (bmi < OVERWEIGHT) {
System.out.println("정상입니다");
System.out.printf("%.1fkg 더 찌면 과체중입니다", normal_weight - weight);
} else if (bmi < FAT) {
System.out.println("과체중입니다");
System.out.printf("정상이 되려면 %.1fkg 빼야 합니다", normal_weight - weight);
System.out.printf("%.1fkg 더 찌면 비만입니다", overweight - weight);
} else {
System.out.println("비만입니다");
System.out.printf("정상이 되려면 %.1fkg 빼야 합니다", overweight - weight);
}
}// 메소드
}
public class 비만도측정 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("몸무게를 입력하세요 : ");
int weight = scan.nextInt();
System.out.println("키를 입력하세요 : ");
int height = scan.nextInt();
Person p = new Person(height, weight);
p.obesity();
}
}
public class BMICalculator {
public static String bmiCal(double result) {
// bmi 측정 함수. 조건도 이 함수에 넣습니다.
if (result < 0) {
return "음수는 말이 안되는 수치입니다.";
}
if (result >= 30) {
return "비만입니다.";
} else if (result >= 25 && result < 30) {
return "과체중입니다.";
} else if (result >= 18.5 && result < 25) {
return "정상입니다.";
}
return "저체중입니다.";
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double weight = scan.nextDouble();
double t = scan.nextDouble();
double result = weight / (t * t);
String bmi = bmiCal(result);
System.out.printf("BMI: %.2f\n", result);
System.out.println(bmi);
}
}
package bmicalculator;
import java.util.Scanner;
public class BMICalculator {
public static void printBMIClassification(double bmiX) {
if (bmiX >= 30)
System.out.println("당신의 Body Mass Index = " + String.format("%.2f", bmiX) + "로서 비만입니다");
else if (bmiX >= 25)
System.out.println("당신의 Body Mass Index = " + String.format("%.2f", bmiX) + "로서 과체중입니다");
else if (bmiX >= 18.5)
System.out.println("당신의 Body Mass Index = " + String.format("%.2f", bmiX) + "로서 정상입니다");
else System.out.println("당신의 Body Mass Index = " + String.format("%.2f", bmiX) + "로서 저체중입니다");
}
public static double calculateBMI(double weightX, double tallX) {
return weightX/(tallX * tallX);
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double weight = input.nextDouble();
double tall = input.nextDouble();
double bmi = calculateBMI(weight, tall);
printBMIClassification(bmi);
}
}
Public static
import java.util.Scanner;
public class cloud14 {
public static float calculateBMI(float weight, float height){
float bmi = weight / (height * height);
return bmi;
}
public static void printBMI(float bmi){
if (bmi >= 30){
System.out.printf("BMI: %.2f\n", bmi);
System.out.println("비만입니다.");
}else if (bmi >= 25){
System.out.printf("BMI: %.2f\n", bmi);
System.out.println("과체중입니다.");
}else if (bmi >= 18.5){
System.out.printf("BMI: %.2f\n", bmi);
System.out.println("정상입니다.");
}else {
System.out.printf("BMI: %.2f\n", bmi);
System.out.println("저체중입니다.");
}
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
float weight = sc.nextFloat();
float height = sc.nextFloat();
float bmi = calculateBMI(weight, height);
printBMI(bmi);
}
}
import java.util.Scanner;
public class Main
{
public static double calculateBMI(double weight, double tall) {
(weight/(tall*tall));
}
public static String printBMIClassification(double BMI){
if(BMI<18.5){
System.out.println("저체중");
}else if(BMI<25){
System.out.println("정상");
}else if(BMI<30){
System.out.println("과체중");
}else
System.out.println("비만");
return "";
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double weight = input.nextDouble();
double tall = input.nextDouble();
double bmi = calculateBMI(weight, tall);
printBMIClassification(bmi);
}
}
import java.util.Scanner;
public class BMICalculator {
public static double calculatorBMI(double weight, double tall) {
return weight / (Math.pow(tall, 2));
}
public static void printBMIClassification(double bmi) {
System.out.printf("BMI: %.2f\n", bmi);
if (bmi < 18.5) {
System.out.println("저체중 입니다.");
} else if (bmi < 25) {
System.out.println("정상 입니다.");
} else {
System.out.println("비만 입니다.");
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double weight = input.nextDouble();
double tall = input.nextDouble();
double bmi = calculatorBMI(weight, tall);
printBMIClassification(bmi);
}
}
public class Quiz_0014 {
public static double calculateBMI(double weight, double tall) {
double bmi = weight / (tall*tall);
return bmi;
}
public static void printBMIClassification(double bmi) {
System.out.printf("BMI: " + "%.2f", bmi);
System.out.println();
if(bmi<18.5){
System.out.println("저체중 입니다.");
} else if (bmi < 25) {
System.out.println("정상 입니다.");
} else if (bmi < 30) {
System.out.println("과체중 입니다.");
}else {
System.out.println("비만 입니다.");
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double weight = input.nextDouble();
double tall = input.nextDouble();
// BMI 지수 계산
double bmi = calculateBMI(weight, tall);
// BMI 지수를 입력하여 비만도 결과 출력
printBMIClassification(bmi);
}
}