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+"当前是非闰年");}
}
}
111 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;
}
}
}
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;
}
}
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("重度肥胖");}
}
} 请为为什么可以用 | 这个符号呢 这个不是或么
我是新手 求解答{:10_254:} 想看
加油 h
{:5_109:} 很有帮助 21121
页:
1
[2]