Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to print the multiple of 5 from n(number user enters )to 1 Letter I only utl

ID: 3710574 • Letter: H

Question

How to print the multiple of 5 from n(number user enters )to 1 Letter I only
utl ploglall 18 do the following using Recursion: a) Compute factorial of a given number b) Compute the sum of n integers c) Print Fibonacci Series for "n" times. d) Compute x power y e) Print the odd numbers from n to 1 f) Prtint the numbers divisible by 6 from n to g) Compute the series 1+5+9+13+ 17+21 -h) Compute the series 1 3 5 7 9 I) Compute the series 2 4 6 8 10 12 j) Compute (m +n -k2 k) Print the even numbers from n to 1 I) Print the multiples of 5 from n to 1

Explanation / Answer

Yup the method is incorrect as the mult call should be inside if condition otherwise it will be called infinitely.

Something like this

public class MyClass {

public static void mult(int n)

{

if(n>1)

{

if(n%5==0)

System.out.println(n);

mult(n-1);

}

}

public static void main(String args[]) {

mult(50);

}

}

The output is

50

45

40

35

30

25

20

15

10

5

Do give a thumbs up and in case there are doubts leave a comment.

But if you want to print each number from 1 to n multiplied by 5 then you can change the method simply

public class MyClass {

public static void mult(int n)

{

if(n>=1)

{

System.out.println(n*5);

mult(n-1);

}

}

public static void main(String args[]) {

mult(50);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote