For each call to the following method indicate what console

For each call to the following method, indicate what console output is produced: public void mystery3(int n) {if (n

Solution

public class Test {

  

   public static void mystery3(int n){

      

       if(n <= 0){

       System.out.print(\"*\");

       }else if(n%2==0){

           System.out.print(\"(\");

           mystery3(n-1);

           System.out.print(\")\");

       }else{

           System.out.print(\"[\");

           mystery3(n-1);

           System.out.print(\"]\");

       }

   }

   public static void main(String args[])

   {

       mystery3(0);

       System.out.println();

       mystery3(1);

       System.out.println();

       mystery3(2);

       System.out.println();

       mystery3(4);

       System.out.println();

       mystery3(5);

   }

}

/*

Sample Output:

*

[*]

([*])

([([*])])

[([([*])])]

*/

 For each call to the following method, indicate what console output is produced: public void mystery3(int n) {if (n Solutionpublic class Test { public static v
 For each call to the following method, indicate what console output is produced: public void mystery3(int n) {if (n Solutionpublic class Test { public static v

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site