Introduction to solving factorial with a recursive method with a return type for the AP Computer Science Exam
Try it yourself and find the pdf notes on Repl.it:
https://repl.it/@StefanWebster/Factorial#Main.java
Visualizer:
http://pythontutor.com/java.html#code=public%20class%20YourClassNameHere%20%7B%0A%20%20%20%20public%20static%20void%20main%28String%5B%5D%20args%29%20%7B%0A%20%20%20%20%20%20%20%20System.out.println%28factorial%285%29%29%3B%0A%20%20%20%20%20%20%20%20System.out.println%28loopFactorial%285%29%29%3B%0A%20%20%7D%0A%0A%20%20%20%20public%20static%20int%20factorial%28int%20n%29%20%7B%0A%20%20%20%20%20%20%20%20if%20%28n%20%3C%3D%200%29%20return%201%3B%0A%20%20%20%20%20%20%20%20return%20n%20*%20factorial%28n-1%29%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20static%20int%20loopFactorial%28int%20n%29%20%7B%0A%20%20%20%20%20%20%20%20int%20total%20%3D%201%3B%0A%20%20%20%20%20%20%20%20for%28int%20i%20%3D%20n%3B%20i%20%3E%200%3B%20i--%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20total%20*%3D%20i%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20return%20total%3B%0A%20%20%20%20%7D%0A%7D&cumulative=false&curInstr=53&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=java&rawInputLstJSON=%5B%5D&textReferences=false