为此,我使用了很多嵌套的 if/else 语句。
我有三个主要分支(活的动物、活的植物、非生物),每个分支都有多个分支。做出60个不同的决定。
我很难让它合作并控制所有 if/else 语句。由于必须重新启动这么多,我还没有太多代码,但目前我在:
System.out.println("Think of Something");
System.out.println("Is it a living animal, living plant, or non-living thing? ");
String user = get.nextLine();
if (user.equals("living animal")); {
//starts animal tree
System.out.println("Does it have feathers, fur, or neither?");
String user2 = get.nextLine();
if (user2.equals("feathers")); {
System.out.println("is it bigger than a soccer ball?");
}
} else if (user2.equals("fur")); {
System.out.println("is it domesticated?");
// end animal tree
} else if (user.equals("living plant")); {
// start plant tree
System.out.println("is it a tree?");
}
} // end method
} //end program
烙印99
至尊宝的传说
繁花如伊
相关分类