5.14 Min and Max Challenge
Okay. It’s time for the next challenge. It’s the minimum and maximum challenge. The challenge is to read the console numbers entered by the user and displayed the minimum and maximum number that the user is entered (that is, if the user is between 5 3 2 for example) the minimum will be 2 and maximum 5. So, before the user enters each number, display the message enter a number. Now, if the user enters an invalid number, Get out of the loop and display the minimum and maximum number that was entered Use a loop while Of course it is with the class scanner as we saw in the previous video I hope you managed to make it work. Now we will add 2 variables Min and max Our min value is set to the highest number an int can contain and our max variable to the lowest. Next, we will scroll until the user enters an invalid number. The "while true" loop is an infinite loop, that is, a loop that does not end. To stop it, we can use a break statement that will exit the loop when the user enters an invalid value. To test if it is a valid number, we will again use the "hasnextInt" method but first we will ask the user to enter a number. Now we will declare a Boolean variable that is equal to the "hasnextInt" method.