トップ・ページの表示 注意書きの表示 掲示板に書き込む前に必ず この ”注意書き”を お読み下さい.

"伊邪那"

   
   

ページの表示順:{ 新しい順/ 古い順}.
初期・ページの表示・位置:{ 先頭ページ/ 末尾ページ}.
1ページ内のスレッド表示数:







<Number>: [00000A59]  <Date>: 2021/07/16 21:42:43
<Title>: Javaデモ/BMI
<Name>: amanojaku@管理人



import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    double[] weight = new double[5];
    double[] height = new double[5];
    Scanner sc = new Scanner(System.in);
    System.out.println("5人分の「体重(kg)、身長(m)」を入力");
    for (int i = 0; i < weight.length; i++) {
      weight[i] = sc.nextDouble();
      height[i] = sc.nextDouble();
    }
    for (int i = 0; i < weight.length; i++) {
      System.out.printf( //
        "weight[%d]=%f, height[%d]=%f%n", i, weight[i], i, height[i]);
      double bmi = calcBMI(weight[i], height[i]);
      String judge = judgeBMI(bmi);
      System.out.printf("bmi=%f, judge=%s%n", bmi, judge);
      System.out.println();
    }
  }
 
  public static double calcBMI(double weight, double height) {
    // BMI=体重(kg)÷(身長(m)×身長(m))
    double bmi = weight / (height * height);
    return bmi;
  }
 
  public static String judgeBMI(double bmi) {
    String judge = null;
    if (bmi < 18.5) { // 18.5未満 やせ
      judge = "やせ";
    } else if (bmi < 25.0) { // 18.5以上25.0未満 標準
      judge = "標準";
    } else if (bmi < 30.0) { // 25.0以上30.0未満 肥満
      judge = "肥満";
    } else { // 30.0以上 高度肥満
      judge = "高度肥満";
    }
    return judge;
  }
}

Block( Address 00000A59 Identity 00000A59 )






ページの表示順:{ 新しい順/ 古い順}.
初期・ページの表示・位置:{ 先頭ページ/ 末尾ページ}.
1ページ内のスレッド表示数:

   
   

管理者用 Password:

  




SMT Version 8.022(+A) Release M6.
Author : amanojaku.


- Rental Orbit Space -