I have an assignment to use a recursive method to print out multiple lines, each line having 3 more spaces in front of it than the previous. Here is a picture of the desired output (https://i.sstatic.net/kKz9z.png).
This is the code I have so far:
public class Prog6d {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int input = scan.nextInt();
System.out.println(printFactorial(input));
}
//Calculates the factorial
public static int printFactorial(int input) {
if (input == 1) {
return 1;
}
System.out.println("factorial(" + input + ")");
System.out.print(" ");
return input*printFactorial(input-1);
}
}
I know how to make the spaces appear correctly using a for-loop, but I have no idea how to do this with recursion.