import java.util.Scanner;如何獲取代碼並將其插入到打印語句中?
公共類權重{
public static void main(String[] args) {
//Make scanner to allow user input
Scanner input = new Scanner (System.in);
//Ask for gender
System.out.println("What is your gender (Male/Female)?: ");
//Store gender as string
String gender = input.nextLine();
//Ask for weight
System.out.println("What is your weight (to closest lb)?: ");
//Stores weight as integer
int userWeight = input.nextInt();
}
public void genderAndWeight (String gender, int userWeight) {
//int femaleWeight = 0;
int maleWeight = 30;
//Determine whether to use male or female int variable
if(gender.equalsIgnoreCase("male"))
{
userWeight -= maleWeight;
}
}
public String conditions(int userWeight)
{
if(userWeight<100)
{
String X = " underweight";
}
else if(100 <= userWeight && userWeight <= 130)
{
String X = " average weight";
}
else if (userWeight > 130)
{
String X = " overweight";
}
else System.out.println("You suck at typing.");
System.out.println("You are" + X);
}
}
我試圖使此代碼找人是否在,平均或超重,但我似乎無法弄清楚如何正確使用該變量。
我不知道該代碼甚至會編譯。 – csmckelvey