I'm fairly new to Java so bear with me. I'm making a recursive method in Java that allows me to input a number X and have the system print each value in decrements of 2 until it reaches 1. (I'll have to add a rule that the scanner can only take odd numbers too). I set up the scanner but it doesn't seem to be picking up the value I assign to n.
public class Recursividad {
public static int Func(int n)
{
if (n != 1)
return 0;
else
return Func(n-2);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int x = Func(n);
System.out.println(x);
}
}
The output is always 0.