Dubli
Dubli

Reputation: 11

Scanner doesnt take the input that i give

I tried everything, after the press 1 to run or press 2 to give him the cannabis it goes to System.out.println("You own: ...!");

questions

Why does my program not take the input that I give it?

Why does it do this?

What did I do wrong?

Everything I used I believe is correct, please help

code

    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");
                }

            }
        }
    }

when I use print store's System.out.println(String s) and blabla...

Upvotes: 0

Views: 41

Answers (1)

Naman
Naman

Reputation: 31868

Primarily, use -

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

instead

print("The cop catched you");

(in all such occurrences) unless you have your own definition of the method print(String str) in the code.

Upvotes: 1

Related Questions