Complete the method, print Multiples(), that takes in a positive integer n, and another positive integer, max. Print out all the multiples of n that are less than or equal to max. Print each multiple on a separate line. For example, if the method is called with n

Respuesta :

Answer:

public static void printMultiples(int n, int max){

    for (int i=1; i<=max; i++){

        if(i%n == 0)

            System.out.println(i);

    }

}

Explanation:

Create a method called printMultiples that takes two parameters n and max

Inside the method, create a for loop that iterates from 1 to max. If i, a number between 1 and max, % n is equal to 0, that means the number is a multiple of n, print the number.