Question: This is a Java method that is supposed to accept an input where if it's a double, it returns the double, but if not, keep

 This is a Java method that is supposed to accept an

This is a Java method that is supposed to accept an input where if it's a double, it returns the double, but if not, keep prompting the user to input a double. However, it isn't working and I do not know why.

112 113 114 115 116 Asks the user for a number. *param console A Scanner from which we can read input *@param prompt The String that should be printed to prompt the user. * @return The number that the user typed in. 118 public static double getDouble(Scanner console, String prompt) 119 120 121 122 123 124 125 126 127 128 System.out.print (prompt); while(!console.hasNextDouble()) System.out.println("That is not a number."); System.out.print(prompt); console.nextDouble(); double answerconsole.nextDouble(); return 0.0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!