xiaoliu66 发表于 2021-5-8 10:38:00

写完了

Njmao 发表于 2021-6-6 13:03:34

感谢分享

liujian973 发表于 2021-6-29 10:25:58

package code_test;
import javax.management.MBeanAttributeInfo;
import javax.swing.text.Style;
import java.util.Scanner;

public class if语句 {
    public static void main(String[] args) {
//      System.out.println("请输入体重");
//      Scanner inputWeight = new Scanner(System.in);
//      double weight = inputWeight.nextDouble();
//      System.out.println("请输入身高");
//      Scanner inputHeight = new Scanner(System.in);
//      double height = inputHeight.nextDouble();
//      calBMI(weight,height);
      System.out.println("1、进行BMI体重计算\n2、进行非闰年测算\n\t\t请输入你的选择");
      Scanner inputOption = new Scanner(System.in);
      int option = inputOption.nextInt();
      if(option ==1){
            calBMI();
      }
      else if(option ==2){
            calLeapYear();
      }
      else {
            System.out.println("!!!!输入错误请重试");
      }

    }

    public static void calBMI(){
      System.out.println("请输入体重 /kg");
      Scanner inputWeight = new Scanner(System.in);
      double weight = inputWeight.nextDouble();
      System.out.println("请输入身高 /m");
      Scanner inputHeight = new Scanner(System.in);
      double height = inputHeight.nextDouble();

      double MBI = weight / (height * height);
      System.out.println("当前BMI值:" + MBI);

      if(MBI >= 35){
            System.out.println("当前重度肥胖");
      }
      else if(MBI >= 30){
            System.out.println("当前中度肥胖");
      }
      else if (MBI >= 27){
            System.out.println("当前轻度肥胖");
      }
      else if (MBI >=24){
            System.out.println("当前体重过重");
      }
      else if (MBI >= 18.5){
            System.out.println("当前体重位正常");
      }
      else {System.out.println("当前体重过轻");}
    }

    public static void calLeapYear(){
      System.out.println("请输入年份");
      Scanner inputYear = new Scanner(System.in);
      int YEAR = inputYear.nextInt();

      if( YEAR % 4 ==0 && YEAR % 100 >0&& YEAR % 400 ==0){
            System.out.println("当前年份"+YEAR+"当前是闰年");
      }
      else {System.out.println("当前年份"+YEAR+"当前是非闰年");}
    }
}

yumson 发表于 2021-8-12 23:32:48

111

Thuu 发表于 2021-8-27 00:27:58

package com.Study.fishc;

import java.util.Scanner;
import java.util.regex.PatternSyntaxException;

/**
* @Description BMI指数
* ----------------------------
* 体重过轻   BMI <18. 5
* 正常范围   18. 5<= BMI < 24
* 体重过重   24<= BMI < 27
* 轻度肥胖   27<= BMI < 30
* 中度肥胖   30<= BMI < 35
* 重度肥胖   35<=BM I
* -------------------------------
* BMI的计算公式是体重(kg) / (身高*身高)
* @Classname BmiWeight
* @Date 2021/8/26 23:40
* @Created by 折腾的小飞
*/
public class BmiWeight {
    public static void main(String[] args) throws Exception {
      System.out.println("请输入身高(m):");
      Scanner scanner = new Scanner(System.in);
      double height = scanner.nextDouble();
      scanner.nextLine(); // 接收空格
      System.out.println("请输入体重(kg):");
      double weight = scanner.nextDouble();
      System.out.println(getBmi(height, weight));
    }
/**
* description: 计算BMI指数
* @since: 1.0.0
* @author: 涂鏊飞tu_aofei@163.com
* @date: 2021/8/27 0:12
* @Param height:
* @Param weight:
* @return: java.lang.String
*/
    private static String getBmi(double height, double weight) throws Exception {

      // 判断是否为0或null
      if (weight == 0 || Double.isNaN(weight) || Double.isNaN(height)) {
            throw new ArithmeticException("被除数不能为0!");
      }
      // 体重为0
      if(height==0){
            throw new Exception("身高异常!");
      }
      double bmi = weight / Math.pow(height, 2);
      String[] msg = {"当前的BMI是:", "身体状态是:"};
      String[] info = {"重度肥胖", "中度肥胖", "轻度肥胖", "体重过重", "正常范围", "体重过轻"};
      if (bmi >= 35) {
            return msg + bmi + "\n" + msg + info;
      } else if (bmi >= 30) {
            return msg + bmi + "\n" + msg + info;
      } else if (bmi >= 27) {
            return msg + bmi + "\n" + msg + info;
      } else if (bmi > 24) {
            return msg + bmi + "\n" + msg + info;
      } else if (bmi > 18.5) {
            return msg + bmi + "\n" + msg + info;
      } else {
            return msg + bmi + "\n" + msg + info;
      }
    }
}

Thuu 发表于 2021-8-27 00:40:48

package com.Study.fishc;

import java.util.Scanner;

/**
* @Description 闰年
* @Classname LeapYear
* @Date 2021/8/27 0:32
* @Created by 折腾的小飞
*/
public class LeapYear {
    public static void main(String[] args) throws Exception {
      System.out.println("请输入要判断的年份:");
      Scanner scanner = new Scanner(System.in);
      int year = scanner.nextInt();
      System.out.println(isLearYear(year));
    }

    private static boolean isLearYear(int year) throws Exception {
      if (Double.isNaN(year) || year<=0){
            throw newException("年份不正确!");
      }
      if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            return true;
      }
      return false;
    }
}

唯有无奈 发表于 2021-9-11 08:29:07

import java.util.Scanner;
/*
        使用Scanner收集身高体重,并计算BMI值
        BMI的计算公式是 体重(kg) / (身高*身高)
       
*/

public class Bmi
{
        public static void main(String[] args){
                Scanner input = new Scanner(System.in);//从键盘接收数据

                float height = 0.0f;
                float weight = 0.0f;
                float BMI = 0.0f;
               
                System.out.println("请输入身高(m):");
                height = input.nextFloat();
                System.out.println("请输入体重(kg):");
                weight = input.nextFloat();
                BMI = weight / ( height * height);
                System.out.println("当前的BMI是:"+BMI);
               
                if(BMI < 18.5)
                        {System.out.println("体重过轻");}
                else if(18.5 <= BMI && BMI < 24)
                        {System.out.println("正常范围");}
                else if(24 <= BMI && BMI < 27)
                        {System.out.println("体重过重");}
                else if(27 <= BMI && BMI < 30)
                        {System.out.println("轻度肥胖");}
                else if(30 <= BMI && BMI < 35)
                        {System.out.println("中度肥胖");}
                else
                        {System.out.println("重度肥胖");}
                       
        }
}

轩少不冷 发表于 2021-12-30 14:44:29

请为为什么可以用 | 这个符号呢 这个不是或么
我是新手 求解答{:10_254:}

yxlml 发表于 2022-1-7 18:17:42

想看

Sunnysun. 发表于 2023-9-24 23:42:05

加油

xx觿xx 发表于 2023-9-25 20:14:26

h

顶聪明的芥子 发表于 2024-2-4 20:32:49

{:5_109:}

宵夜yeyeyeye 发表于 2024-4-23 08:50:03

很有帮助
页: 1 [2]
查看完整版本: 【JAVA练习题01】【控制流程】JAVA的IF 条件语句--BMI&闰年