Spacing in Java - 3.27.1: LAB: Number pattern

56 Views Asked by At

I don't understand how to do a new line at the end? I have included a picture that shows what my answer looks like with the whitespacing wrong and then shows how they want the output to look.

here is my code:

import java.util.Scanner;

public class NumberPattern {
    public static void printNumPattern(int num1, int num2) {
       //print num1
       System.out.print(num1);
       //check if num1 is non-negative
       if (num1 >= 0) {
           //print a space
           System.out.print("  ");
           //recursively call printNumPattern, pass num1-num2 as new num1,
           //and same num2 as arguments
           printNumPattern(num1-num2, num2);
           //once above call is returned, print a space and then num1 again
           System.out.print(" "+num1);
       }
    }

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        int num1;
        int num2;

        num1 = scnr.nextInt();
        num2 = scnr.nextInt();
        printNumPattern(num1, num2);
    }
}

Java problem enter image description here

0

There are 0 best solutions below