Write an input validation loop that asks the user to enter a

Write an input validation loop that asks the user to enter a number in the range of 10 through 25.

Solution

ValidationLoop.java

import java.util.Scanner;

public class ValidationLoop {

   public static void main(String[] args) {
       //Declaring variables
       int num;
      
       //Scanner class is used to read the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       /* This loop continues to execute until the user
       * enters a valid number between 10 and 25 inclusive
       */
       while(true)
       {
       //Getting the number entered by the user  
       System.out.print(\"\ Enter a number :\");
       num=sc.nextInt();
      
       /* Checking If the number is in the range or not.
       * if Not,Display error message
       * And Prompts the user to enter a valid number again
       */
       if(num<10 ||num>25)
       {
           //Displaying an error message
           System.out.println(\":: Invalid Number.Number must be between (10 -25) inclusive ::\");
           continue;
       }
       else
           break;
       }

   }

}

______________________

Output:

Enter a number :45
:: Invalid Number.Number must be between (10 -25) inclusive ::

Enter a number :7
:: Invalid Number.Number must be between (10 -25) inclusive ::

Enter a number :23

____Thank You

 Write an input validation loop that asks the user to enter a number in the range of 10 through 25.SolutionValidationLoop.java import java.util.Scanner; public

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site