我从 java 开始,在通过 BMI 计算器返回正确的值时遇到问题。我非常感谢你的帮助!
亲切的问候, 安迪...
public class bmirechner {
public static void main(String[] args) {
String ergebnis ="";
bmirechner(ergebnis);
System.out.println(ergebnis);
}
public static String bmirechner(String ant){
int kg=0;
float length=0;
double bmi=0;
Scanner sc = new Scanner(System.in);
System.out.println("Bitte geben Sie ihr Körpergewicht ein.");
kg = sc.nextInt();
System.out.println("Bitte geben Sie ihre Größe ein.");
length = sc.nextFloat();
bmi = kg/(length*length);
if(bmi>=18.5&&bmi<=24) {
return ant="Normalgewicht";
}
else if(bmi>=24&&bmi<30) {
return ant="Übergewicht";
}
else if(bmi>=30&&bmi<35) {
return ant="Adipositas Grad 1";
}
else if(bmi>=35&&bmi<40) {
return ant="Adipositas Grad 2";
}
else if(bmi>40) {
return ant="Adipositas Grad 3";
}
else return ant="nicht vorhanden";
}
}
最佳答案
我对java不太熟悉,但我正在考虑return ant="Normalgewicht";
部分。我只会写 return "Normalgewicht";
关于java - 在两种不同方法之间传递字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50124316/