I'm confused i'm suppose to get a positive int from user using recursion, the user can input words, and also numbers.(Words and negative numbers are invalid), Not sure what i'm doing wrong. I'm sorry forgot to ask the question, well i'm getting compiler error, when I try to compile it, something is wrong with my Scanner, I was reading an it says I have to use an argument for the users input, I'm not sure how to, and the second question was, how do I let the code to repeat if the user inputs n<0 or a word, such as taxes. thank you
import java.util.*;
public class Recursion {
private static int getPositiveInt(Scanner keyboard) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a positive interger, n");
int n = keyboard.nextInt();
if (n > 0) {
return n;
}
else { //here the code should rerun if invalid input, but I cant figure it out
System.out.println("enter a positive number");
}
}
}