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

Java 1. Write a program that calls a recursive method called multiply that takes

ID: 3861469 • Letter: J

Question

Java

1. Write a program that calls a recursive method called multiply that takes two integer parameters a and b, where a and b are both positive integers.You can only use the + or–for multiplication.

2. Write a recursive method called writeSquares that accepts an integer parameter n and prints the first n squares separated by commas, with the evensquares in descending order followed by the oddsquares in ascending order. For example, writeSquares(11); prints the following output: 100 6436 16 41 9 25 49 81 121

Explanation / Answer

/**

* Question 1

*/

import java.util.Scanner;


public class Main
{
public static void main(String[] args)
{
   Scanner input = new Scanner(System.in);
   int a = input.nextInt();
   int b = input.nextInt();
Main ob = new Main();
int c = ob.multiply(a, b);
System.out.println("multiplication of number is : "+c);
}

public int multiply(int a, int b) {
   if(a == 0){
       return 0;
   }
   else
       return b+multiply(a - 1,b);
}
}

/**

* Question 2

*/

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