0

The code is asking for double value to be enter. I'm testing to make sure that only a double value is enter. I've also do this code with a try/catch and get the same think. I've tested this code in a scratch file it works. But no in my code. if you don't put in the userInput.nextLine() then you get a endless loop going.

    boolean done = false;
    double hold = 0.0;

    while (!done) {
        System.out.println("HOW MUCH DO YOU WANT TO SPEND ON YOUR OXEN TEAM");

        if(userInput.hasNextDouble()) {

            hold = userInput.nextDouble();

            if (hold <= 199) {
                System.out.println("NOT ENOUGH");

            } else if (hold >= 299) {
                System.out.println("TOO MUCH");

            } else {
                this.oxen = hold;
                done = true;
            }

        } else {

            userInput.nextLine();
            System.out.println(numberOnly);
        }

    }

enter image description here You see that I have to type the number 3 times before it will pick it up. HELP!

I've tried this code plus I do a try/catch and get the same think. You should only have to type in the number one times and it should pick it up.

Progman
  • 16,827
  • 6
  • 33
  • 48

0 Answers0