Answer:
See explaination
Explanation:
Code;
import java.util.Scanner;
public class NumberPattern {
public static int x, count;
public static void printNumPattern(int num1, int num2) {
if (num1 > 0 && x == 0) {
System.out.print(num1 + " ");
count++;
printNumPattern(num1 - num2, num2);
} else {
x = 1;
if (count >= 0) {
System.out.print(num1 + " ");
count--;
if (count < 0) {
System.exit(0);
}
printNumPattern(num1 + num2, num2);
}
}
}
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);
}
}
See attachment for sample output