使用java中的嵌套if语句的一些条件未满足

时间:2014-09-29 15:28:49

标签: java

import java.util.Scanner;
class GateWay{

public static void main(String [] args){
boolean male = true;
boolean female = false;

Scanner inputGender = new Scanner (System.in);
System.out.println("Are you male, true/ false: ");
String gender = inputGender.next();

if(true){
System.out.println("Type your age Sir...");

}else if(false){
System.out.println("Type your age Maam...");}

Scanner inputAge = new Scanner (System.in);
System.out.println("Please enter your age: ");
int age = inputAge.nextInt();


if(male == false){ 
if( age < 18 ){
System.out.println("you are too young a girl, go home");

}else if( age > 40 ){
System.out.println("you are too old , go home your body is now weak");

} else if((age > 18 ) && (age <= 40 )){System.out.println("Enter and Enjoy Maam");
}
}

if (male == true){
if( age < 22 ){
System.out.println("you are too young a boy, go home");

}else if( age > 80 ){
System.out.println("you are too old , go home your body can no longer take alcohol");

} else if((age > 22 ) && (age <= 80 )){System.out.println("Enter and Enjoy Sir");
}
}
}

}

//我有这个代码来过滤一个酒吧的流量。现在问题是没有满足女性的所有条件。代码只是执行男性条件。我如何去纠正这个

2 个答案:

答案 0 :(得分:2)

/**
  You will always enter this statement.
  A good IDE should indicate this as suspect
 */
if(true){ 

您可能想测试输入值:

if(gender.equals("true")){

答案 1 :(得分:0)

//如果true并不意味着什么,我的意思是编译器无法理解该做什么在这里给出一些条件

if(gender.equals(true)){
System.out.println("Type your age Sir...");

}else{   // if u have only two conditions then no need to give else if just else is sufficient
System.out.println("Type your age Maam...");}