我正在编写一个程序,用户输入身高和体重,然后从中计算身体质量指数。它使用单独的高度,重量和BMI方法,这些方法从main调用。我遇到的问题是我完全不知道如何将权重和高度方法的输入放入BMI方法。这就是代码的样子:
public class BMIProj {
static Scanner input = new Scanner(System.in);
public static int heightInInches()
{
System.out.println("Input feet: ");
int x;
x = input.nextInt();
System.out.println("Input Inches: ");
int y;
y = input.nextInt();
int height = x * 12 + y;
return height;
}
public static int weightInPounds()
{
System.out.println("Input stone: ");
int x;
x = input.nextInt();
System.out.println("Input pounds ");
int y;
y = input.nextInt();
int weight = x * 14 + y;
return weight;
}
public static void outputBMI()
{
}
public static void main(String[] args) {
heightInInches();
weightInPounds();
outputBMI();
}
提前致谢。
答案 0 :(得分:0)
您可以将方法的输出分配给如下参数:
int weight = weightInPounds();
调用方法时,可以传入参数:
outputBMI(weight);
其余由你决定。
答案 1 :(得分:0)
我建议你在java中学习更多,特别是变量,声明,初始化等。还要学习类,构造函数等。
我做了为你计算bmi的屈膝礼
无论如何
public class BMIProj {
static Scanner input = new Scanner(System.in);
// Class vars
int height;
int weight;
double bmi;
//Constructor
public BMIPrj(){
//Initialize vars
height = 0;
weight = 0;
bmi = 0;
}
public static void heightInInches()
{
System.out.println("Input feet: ");
int x;
x = input.nextInt();
System.out.println("Input Inches: ");
int y;
y = input.nextInt();
int height = x * 12 + y;
return height;
}
public static void weightInPounds()
{
System.out.println("Input stone: ");
int x;
x = input.nextInt();
System.out.println("Input pounds ");
int y;
y = input.nextInt();
int weight = x * 14 + y;
return weight;
}
public static void outputBMI()
{
System.out.println("BMI: " + (( weight / height ) x 703));
}
public static void main(String[] args) {
heightInInches();
weightInPounds();
outputBMI();
}