I am a bit confused by your code; in some places you mentioned factorials. Your factorial formula is, I am afraid, incorrect; I think you will get
0! = 0.
Don't talk about recursion and loops. It is recursion OR it is a loop. Actually, in many cases, a loop and a recursive solution are equivalent to each other.
This is how I would write a factorial program. This is a very simple and naïve program, it ignores the fact that there is no such thing as a factorial of a negative number. It also forgets that you will get an overflow error for an argument > 12 (I think you can calculate 21! with a
long).
Also note the use of ?: instead of an
if‑else
Another thing: I am using a simpler base case than you did: plain simple 0.
That might not give you the sum of 0+2+4+6+8+10, but it does give you a good idea what a simple recursive method looks like.
And . . . welcome to the Ranch