Question

//1. Write out the output for eaching of following: /* Consider this function. void myMethod( int...

//1. Write out the output for eaching of following: /* Consider this function. void myMethod( int counter) { if(counter == 0) return; else { System.out.println(""+counter); myMethod(--counter); return; } }

Homework Answers

Answer #1

function myMethod(int counter) will print the number starting from counter value till 1. at each recursive call counter value is decremented by 1. When counter value reaches 0, the function ends beacuse of if condition where it checks if counter is 0 then return from method and control goes back to main method.

code:-

Ouput

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
What is the output of the following function and function call? void calculateCost(int count, float& subTotal,...
What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float taxCost); float tax = 0.0, subtotal = 0.0; calculateCost(15, subtotal,tax); cout << "The cost for 15 items is " << subtotal       << ", and the tax for " << subtotal << " is " << tax << endl; //end of fragment void calculateCost(int count, float& subTotal, float taxCost) {       if ( count < 10)       {                   subTotal = count *...
What is the output of the following function and function call? void calculateCost(int count, float& subTotal,...
What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float taxCost); float tax = 0.0, subtotal = 0.0; calculateCost(15, subtotal,tax); cout << "The cost for 15 items is " << subtotal       << ", and the tax for " << subtotal << " is " << tax << endl; //end of fragment void calculateCost(int count, float& subTotal, float taxCost) {       if ( count < 10)       {                   subTotal = count *...
Given the following function in C++: int main(void) { int a = 2; int b =...
Given the following function in C++: int main(void) { int a = 2; int b = myFunction(a); a = b + 1; b = myFunction(a); cout << ”b = ” << b << endl; return 0; } int z = myFunction(int x) { static int n = 0; n = n + 1; int z = x + n; return z; } What is printed by the cout on the screen?
Write a C function to compute the following output (int) based on two input (int) variables:...
Write a C function to compute the following output (int) based on two input (int) variables: output = a*a + b*b - 2*a*b If the value of output is '0', then return -1 instead. Call the C function 4 times from main() with values of 'a' and 'b' as follows and print output values for each case. a = 3, b = 4 a = 1, b = 1 a = -2 b = 3 a = -4 b =...
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL...
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL && pointVar2 == NULL) {       printf("Pointer is null\n");    }    else if (*pointVar2 > *pointVar1) {       printf("%p\n", *pointVar2);    }    else if (*pointVar1 > *pointVar2) {       printf("%p\n", *pointVar1);    } } int main() {    int num1 = 5;    int num2 = 9;       CheckValue(&num1, &num2);           return 0; } a. 0 b. 5 c. 9 d. Pointer is null e....
Analyze the following program and write down the output. # include <iostream> using namespace std;    void...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void modifyArray( int [ ], int );    void modifyElement ( int );      int main( ) {   const int arraySize = 8;   int a[arraySize] = { 2, -2, 10, -3, -1 ,0, 10, -5 };      modifyArray ( a, arraySize);      for ( int i =0; i < arraySize; i++)               cout << a[i] << ‘  ’;         modifyElement ( a[4] );          for ( int i =0; i <...
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void Ge
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void GenerateFromArray(void); /************************************************************************************/ /************************************************************************************/ int main(void) { /* This is the main() program. It should call the functions ScanArray() and GenerateFromArray() */ GenerateFromArray(); system("pause"); return 0; } /*************************************************************************************** Define this function to scan the elements of an array from the given data file "ArrayInp.dat". If the input file is not found, or contains invalid data, the function should return a 0 and print an error message. If the input...
Give the output of the following program. Then explain what the foo() method does, in general,...
Give the output of the following program. Then explain what the foo() method does, in general, for a given input. Is foo() a tail-recursive method? Why or why not? class SomeThing {     public static void main(String args[]) {         System.out.println(foo(6));     }     private static int foo(int input) {         if (input <= 0) {             throw new RuntimeException("invalid input");         }         else if (input == 1) {             return 1;         }         else if (input %...
[ Write in C not C++] Define a C function void placeElements(int *a, int i, int...
[ Write in C not C++] Define a C function void placeElements(int *a, int i, int j) that inter-exchange the array elements at indexiandj. For a[] = {5,7,4,2,1},a callto placeElements(a,2,4) makesa[] = {5,7,1,2,4}. [8]