The following code segment has been created. the code can be placed in a method. The code keeps asking the user to enter
Posted: Fri May 20, 2022 5:49 pm
The following code segment has been created. the code can be placed in a method. The code keeps asking the user to enter a double value until the user provides a valid input. Once a valid input is entered the loop ends and the method returns the value However it has an infinite loop. Fill in the blank so that the method works. int done = 0; double input = 0; while (done!= -1) { try { System.out.print("Enter an double: "); input = kb.nextDouble(); } catch(Exception e) { System.out.println("You did not enter a valid input "); } kb.nextLine(); } return input;