0

Java

Can someone help me code this i’m kinda confused. Call a method named getVelocity that returns an integer and has a Scanner parameter. This method must use a either a while loop or a do-while loop to prompt the user to enter the maximum wind velocity (speed) and return it. A valid value for the maximum wind velocity is between 2 and 50 (inclusive). As long as the value is not valid, display a message saying the value is invalid and prompt the user to enter the value again

23rd Apr 2021, 11:08 PM
Diana Lopez
3 Answers
+ 3
static int getVelocity(Scanner sc) { System.out.print("Enter maximum wind velocity : "); int v = sc.nextInt(); while(!(v >= 2 && v <= 50)) { System.out.print("\nInvalid input. Enter again : "); v = sc.nextInt(); } return v; }
24th Apr 2021, 2:30 AM
Soumik
Soumik - avatar
+ 1
I see what i did wrong now thank you so much for the help :) I appreciate it
24th Apr 2021, 5:07 AM
Diana Lopez
+ 1
You're welcome Diana Lopez ^_^
24th Apr 2021, 7:44 AM
Soumik
Soumik - avatar