1,BMI体质指数测试
BMI=体重(kg)/(身高*身高),接收输入的身高和体重,然后输出结果:
过轻:低于18.5
正常:18.5~22.9
偏胖:23~24.9
肥胖:25~29.9
重度肥胖:高于30
package java4;
import java.util.Scanner;
public class practise {
public static void main(String[] args) {
System.out.println("请输入体重(kg)");
double weight = new Scanner(System.in).nextDouble();
System.out.println("请输入身高(m)");
double height = new Scanner(System.in).nextDouble();
getbmi(height,weight);
}
public static void getbmi(double height, double weight) {
double bmi = weight / (height * height);
String b="";
if (bmi < 18.5) {
b="过轻";
}
else if (bmi <= 22.9 && bmi > 18.5 ) {
b="正常";
}
else if (bmi <= 24.9 && bmi > 22.9) {
b="偏胖";
}
else if (bmi <= 29.9 && bmi > 24.9) {
b="肥胖";
}
else if (bmi >= 30) {
b="重度肥胖";
}
System.out.println("您的体质指数为:" + bmi);
System.out.println("您的体重属于:"+b);
}
}
2,求一个数的绝对值
package java4;
import java.util.Scanner;
public class practise {
public static void main(String[] args) {
System.out.println("请输入需要阶乘的数字");
int x =new Scanner(System.in).nextInt();
jie(x);
}
public static void jie(int x) {
long result=1;
if (x < 0){
System.out.println("负数无阶乘");
return;
}
if (x == 0){
System.out.println("0的阶乘为1");
return;
}
if (x > 0){
for (int i = 1; i <= x ; i++){
result *= i;
}
System.out.println("这个的阶乘为:"+result);
}
}
}
3,求鸡兔同笼:共有36个头,98只脚,求鸡和兔各有多少只?
package java4;
public class practise {
public static void main(String[] args) {
for (int ji=0,tu=36;ji<=36;ji++,tu--){
if (ji*2+tu*4==98){
System.out.println("鸡有" +ji +"只,兔有" +tu+ "只");
}
}
}
}
4,求数字阶乘:由键盘输入阶乘数字,计算出该数字的阶乘j结果
(注意:负数无阶乘,0的阶乘为1)
package java4;
import java.util.Scanner;
public class practise {
public static void main(String[] args) {
System.out.println("请输入需要阶乘的数字");
int x =new Scanner(System.in).nextInt();
jie(x);
}
public static void jie(int x) {
long result=1;
if (x < 0){
System.out.println("负数无阶乘");
return;
}
if (x == 0){
System.out.println("0的阶乘为1");
return;
}
if (x > 0){
for (int i = 1; i <= x ; i++){
result *= i;
}
System.out.println("这个的阶乘为:"+result);
}
}
}
5,打印50以内除了尾数为2,6,8的所有数
package java4;
public class practise {
public static void main(String[] args) {
for (int i = 1; i <= 50; i++) {
if (i % 10 == 2||i % 10 == 8||i % 10 == 8) {continue;}
System.out.println(i);
}
}
}
标签:Java,void,练习,System,println,第二天,阶乘,public,out From: https://blog.csdn.net/weixin_45449264/article/details/142466123