我尝试了所有内容,在按下1
后运行或按2
向他提供大麻,然后转到System.out.println("You own: ...!");
为什么我的程序不接受我提供的输入?
为什么这样做?
我做错了什么?
我用过的所有东西我都相信是正确的,请帮忙
while (canabisOwn > 0) {
System.out.println("You own: " + canabisOwn + " canabis!");
System.out.println("You have " + health + " health");
System.out.println("You can run with: " + mySpeed + " km/hr");
System.out.println("\n \t What would you like to do?");
System.out.println("\t 1. Sell");
System.out.println("\t 2. Find dealer");
System.out.println("\t 3. Smoke");
String input = in.nextLine();
if (input.equals("1")) {
if (peopleC > CopC) {
canabisOwn -= peopleCBC;
System.out.println("You found someone and you sold " + peopleCBC + " canabis");
} else if (CopC > peopleC) {
print("A cop found you. Risk and run or give him the canabis?");
print("Press 1 to run ");
print("Press 2 to give him the canabis");
input = in.nextLine();
if (input.equals("1")) {
if (CopSpeed > mySpeed) {
health -= 30;
print("The cop catched you");
print("You dont have any canabis,you have to find some");
}
}
else if (input.equals("2")) {
canabisOwn -= canabisOwn;
print("You dont have any canabis");
}
}
}
}
当我使用print store' s System.out.println(String s)
和blabla ...
答案 0 :(得分:1)
主要使用 -
System.out.println("The cop catched you");
而不是
print("The cop catched you");
(在所有此类事件中),除非您在代码中有自己的方法print(String str)
定义。