BMI指数
import java.util.Scanner;
public class BmiTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入身高(m): ");
double height = scan.nextDouble();
System.out.println("请输入体重(kg): ");
double weight = scan.nextDouble();
String state = "";
double bmiNumber = weight / (height * height);
if(bmiNumber < 18.5 && bmiNumber > 0){
state = "体重过轻";
}else if(bmiNumber >= 18.5 && bmiNumber <24){
state = "正常范围";
}else if(bmiNumber >= 24 && bmiNumber < 27){
state = "体重过重";
}else if(bmiNumber >= 27 && bmiNumber < 30){
state = "轻度肥胖";
}else if(bmiNumber >= 30 && bmiNumber <35){
state = "中度肥胖";
}else if(bmiNumber >= 35){
state = "重度肥胖";
}
System.out.println("当前的BMI是: " + bmiNumber);
System.out.println("身体状态是: " + state);
}
}
判断闰年import java.util.Scanner;
public class LeapYearTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入一个年份: ");
int year = scan.nextInt();
if(year % 4 == 0 && year % 100 != 0 || year % 400 ==0){
System.out.println(year + "年是闰年");
}else{
System.out.println(year + "年不是闰年");
}
}
}
|