Answer:
import java.util.*;
public class num2 {
public static void main(String[] args) {
//Set the Value of the argument
int val = 5;
//Call the method
int returnedNum = testInteger(val);
//Use a While to continously call the method as long as the returned value is not 0
while(returnedNum != 0){
int rt = testInteger(val);
//Break out of loop when the user enters correct value and the return is 0
if(rt == 0){
break;
}
}
}
//The Method definition
public static int testInteger(int val){
//Prompt and receive user input
System.out.println("Enter a number");
Scanner in = new Scanner(System.in);
int userNum = in.nextInt();
//Check different values using if and else statements
if(userNum > val){
System.out.println("Too High");
return 1;
}
else if(userNum < val){
System.out.println("Too Low");
return -1;
}
else{
System.out.println("Got it");
return 0;
}
}
}
Step-by-step explanation:
This is solved with Java Programing Language
Pay close attention to the comments provided in the code
The logic is using a while loop to countinually prompt the user to enter a new number as long as the number entered by the user is not equal to the value of the argument already set to 5.