I am a novice programmer, just learning how to use recursions. Sorry if my question is very basic, but I wish to know why my code outputs extra values. I have run the code multiple times, and it outputs extra values. The point of the code is to take "Pi" and take the digits and "x2" it. So, 3.1415 = 6 2 8 2 10. The output that I got is below, thanks for your help!
public class printPi
{
static int x = 1;
static double pi = .314159265359;
public static void main(String[] args)
{
piPrinter(pi);
}
public static void piPrinter(double pi01)
{
if(x!=0)
{
pi = pi*10;
x = (int)(pi%10);
x=x*2;
System.out.println(x);
piPrinter(pi);
}
else
System.out.println("done.");
}
}
My Output:
6
2
8
2
10
18
4
12
10
6
10
16
18
18
18
18
12
12
12
0
done.(With new lines between each #)