-4
私はプログラミングとJavaについてとても新しいです。彼らが正しい入力を選択した場合、変数に値を代入する場合はelseを使用しようとしています。しかし、コンパイルしようとするたびに変数を見つけることができないと言います。Javaでelse ifを使用して値を割り当てよう
import java.util.Scanner;
public class TDEE
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
double tdee = 0.0;
System.out.print("Please enter your name: ");
String name = in.next();
System.out.print("Please enter your BMR: ");
double bmr = in.nextDouble();
System.out.print("Please enter your Gender (M/F): ");
String gender = in.next();
System.out.println();
// providing menu items
System.out.println("Select your activity level: ");
System.out.println("[0] Resting (Sleeping. Reclining)");
System.out.println("[1] Sedentary (Minimal Movement)");
System.out.println("[2] Light (Sitting, Standing)");
System.out.println("[3] Moderate (Light Manual Labor, Dancing, Riding Bike)");
System.out.println("[4] Very Active (Team Sports, Hard Manual Labor)");
System.out.println("[5] Extremely Active (Full-time Athlete, Heavy Manual Labor)");
System.out.println();
// accept user choice with a Scanner class method
System.out.print("Enter the number corresponding to your activty level(0,1,2,3,4, or 5): ");
String choice = in.next();
System.out.println();
if(choice.equalsIgnoreCase("0"))
{
double activityFactor = 1.0;
}
else if(choice.equalsIgnoreCase("1"))
{
double activityFactor = 1.3;
}
else if(choice.equalsIgnoreCase("2") && "M".equals(gender))
{
double activityFactor = 1.6;
}
else if(choice.equalsIgnoreCase("2") && "F".equals(gender))
{
double activityFactor = 1.5;
}
else if(choice.equalsIgnoreCase("3") && "M".equals(gender))
{
double activityFactor = 1.7;
}
else if(choice.equalsIgnoreCase("3") && "F".equals(gender))
{
double activityFactor = 1.6;
}
else if(choice.equalsIgnoreCase("4") && "M".equals(gender))
{
double activityFactor = 2.1;
}
else if(choice.equalsIgnoreCase("4") && "F".equals(gender))
{
double activityFactor = 1.9;
}
else if(choice.equalsIgnoreCase("5") && "M".equals(gender))
{
double activityFactor = 2.4;
}
else if(choice.equalsIgnoreCase("5") && "F".equals(gender))
{
double activityFactor = 2.2;
}
else
{
System.out.println("You did not choose a valid manu option.");
}
tdee = bmr * activityFactor;
System.out.println();
System.out.println("Name: " + name + " Gender: " + gender);
System.out.println("BMR: " + bmr + " Activity Factor: " + activityFactor);
System.out.println("TDEE: " + tdee);
}
}
[構文質問IF ELSE(Java)]の可能な複製(http://stackoverflow.com/questions/1496435/syntax-question-if-else-java) – Nikhil