Computer Science, asked by xamphobic, 4 months ago

What will be the output of the following program?
public class Phone Rings
{
public static void main(String[] args){
System.out print(call(53)+ " "+call(25));
}
public static int call(int number){
System.out.print(number+":");
if(number %7==0){
return 77;
if (number%6==0){
return 66;
}
return call(number - 1);
}​

Answers

Answered by sonalkhoond7
0

Answer:

Happy Makar Sakranti

Answered by akansha804
0

Answer:

The correct output to this question is:

53:52:51:50:49:25:24:77 66

Explanation:

According to the given program,

  1. initialized a class with the name as PhoneRings
  2. A call function (recursive type) with a single parameter that returns an integer
  • it consists, of a print statement that prints every number which is being passed
  • a control statement checks a condition, whether the number is divisible by 7. If so it returns a value of 77        
  • a control statement checks a condition, whether the number is divisible by 6. If so it returns a value of 66
  • finally, a recursive call will repeatedly happen until the conditions are satisfied

    3. In the main function, two function calls are given which get the values and the output will be printed.

Function call 1,

At first 53 is passed then

output - 53:

next 53 - 1 = 52

output - 53:52:

52 - 1 = 51

output - 53:52:51:

51 - 1 = 50

output - 53:52:51:50:

50 - 1 = 49

output - 53:52:51:50:49:

Now, the condition satisfies and the function returns 77

Function call 2,

At first 25 is passed then

output - 53:52:51:50:49:25:

next 25 - 1 = 24

output - 53:52:51:50:49:25:24:

Now, the condition satisfies and the function returns 66

Hence the final output is, 53:52:51:50:49:25:24:77 66 (a gap between 77 and 66 is given in the print statement)

Program:

public class PhoneRings

{

   public static void main(String[] args){

       System.out.print(call(53)+ " "+call(25));

   }

   public static int call(int number){

       System.out.print(number+":");

       if(number %7==0){

           return 77;

       }

       if (number%6==0){

           return 66;

       }

       return call(number - 1);      

   }

}

output:

53:52:51:50:49:25:24:77 66

Click here for more about java programming:

https://brainly.in/question/15262300

Click here for more about recursion:

https://brainly.in/question/634885

Similar questions