2017-03-05 64 views
0

我什么都试过了输入时,按下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"); 
       } 

      } 
     } 
    } 

当我使用打印店的System.out.println(String s)和布拉布拉......

+0

你需要让问题更清楚一点。请标记您正在尝试的步骤以及您提供的输入和输出以及预期的内容。 – nullpointer

+0

...顺便说一句,有很多变量定义在您共享的代码范围之外。您也必须参考它们分享详细信息(值)。 – nullpointer

+2

也确保您发布的代码至少完整,缺少一些大括号'}',请在完整代码后填入 – Yazan

回答

1

首先,使用 -

System.out.println("The cop catched you"); 

改为

print("The cop catched you"); 

(在所有这些情况下),除非您在代码中具有您自己的方法print(String str)的定义。