I have a code which I would like to have three variables call on a method that reads user input and determine if it is an integer(if not reprompt the user), then return the input to the variable. I get the following compiler error when I try to compile:
Error: The method getInt(int) in the type Methods is not applicable for the arguments (java.util.Scanner)
Here is my code:
import java.util.Scanner;
public class Methods{
public static void main(String [] arg){
Scanner scan=new Scanner(System.in);
int a,b,c;
System.out.println("Enter three ints");
a = getInt(scan.nextInt());
b = getInt(scan.nextInt());
c = getInt(scan.nextInt());
}
public static int getInt(String input){
Scanner scan=new Scanner(System.in);
int num = 0;
while (num <1) {
if(scan.hasNextInt()) {
int number = scan.nextInt();
num +=1;
}
else{
System.out.println("Invalid input. Please enter an integer value.");
input.next();
}
}
}
Any help you could give would be appreciated!