Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中使用嵌套if语句的某些条件不满足 import java.util.Scanner; 类网关{ 公共静态void main(字符串[]args){ 布尔男性=真; 布尔女性=假; 扫描仪输入性别=新扫描仪(System.in); System.out.println(“你是男性吗,对/错:”); 字符串性别=inputGender.next(); 如果(真){ System.out.println(“键入您的年龄,先生…”); }else if(false){ System.out.println(“键入您的年龄…”);} 扫描仪输入=新扫描仪(System.in); System.out.println(“请输入您的年龄:”; int age=inputAge.nextInt(); 如果(男性==false){ if(年龄40岁){ System.out.println(“你太老了,回家吧,你的身体现在很虚弱”); }如果((年龄>18岁)和(&(年龄80岁){ System.out.println(“你太老了,回家吧,你的身体再也不能喝酒了”); }如果((年龄>22岁)和(&)年龄_Java - Fatal编程技术网

java中使用嵌套if语句的某些条件不满足 import java.util.Scanner; 类网关{ 公共静态void main(字符串[]args){ 布尔男性=真; 布尔女性=假; 扫描仪输入性别=新扫描仪(System.in); System.out.println(“你是男性吗,对/错:”); 字符串性别=inputGender.next(); 如果(真){ System.out.println(“键入您的年龄,先生…”); }else if(false){ System.out.println(“键入您的年龄…”);} 扫描仪输入=新扫描仪(System.in); System.out.println(“请输入您的年龄:”; int age=inputAge.nextInt(); 如果(男性==false){ if(年龄40岁){ System.out.println(“你太老了,回家吧,你的身体现在很虚弱”); }如果((年龄>18岁)和(&(年龄80岁){ System.out.println(“你太老了,回家吧,你的身体再也不能喝酒了”); }如果((年龄>22岁)和(&)年龄

java中使用嵌套if语句的某些条件不满足 import java.util.Scanner; 类网关{ 公共静态void main(字符串[]args){ 布尔男性=真; 布尔女性=假; 扫描仪输入性别=新扫描仪(System.in); System.out.println(“你是男性吗,对/错:”); 字符串性别=inputGender.next(); 如果(真){ System.out.println(“键入您的年龄,先生…”); }else if(false){ System.out.println(“键入您的年龄…”);} 扫描仪输入=新扫描仪(System.in); System.out.println(“请输入您的年龄:”; int age=inputAge.nextInt(); 如果(男性==false){ if(年龄40岁){ System.out.println(“你太老了,回家吧,你的身体现在很虚弱”); }如果((年龄>18岁)和(&(年龄80岁){ System.out.println(“你太老了,回家吧,你的身体再也不能喝酒了”); }如果((年龄>22岁)和(&)年龄,java,Java,您可能需要测试输入值: /** You will always enter this statement. A good IDE should indicate this as suspect */ if(true){ //如果真的在这里没有任何意义,我的意思是编译器不能理解在这里做什么,请给出一些条件 if(gender.equals("true")){ 如果(true)无效,如果(false)将永远不会执行。否则如果(false)无效(如果可能)更无用的是。你从来没有根据用户

您可能需要测试输入值:

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

//如果真的在这里没有任何意义,我的意思是编译器不能理解在这里做什么,请给出一些条件

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

如果(true)
无效,
如果(false)
将永远不会执行。
否则如果(false)
无效(如果可能)更无用的是。你从来没有根据用户输入设置
male
female
的值,因此
male
总是正确的。你真的需要坐下来拿一些纸和铅笔来解决这个问题。不仅
else if(false)
永远不会命中,而且
if(male==false){
也不会命中,因为你永远不会更改变量
male
的值。你把
gender
作为一个字符串输入,什么也不做。坐在那里用纸和铅笔写下你的变量和它们的值,当你在代码中找到它们时。追踪逻辑,看看它会去哪里/不会去哪里。你也应该这样添加我需要验证,以确保您从用户处获得字符串“true”或“false”,但这只有在您解决了这里的逻辑问题之后才能进行。
if(gender.equals("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...");}