1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Bas_tet [7]
2 years ago
9

What is output? public class MathRecursive { public static void myMathFunction(int a, int r, int counter) { int val; val = a*r;

System.out.print(val+" "); if (counter > 4) { System.out.print("End"); } else { myMathFunction(val, r, counter + 1); } } public static void main (String [] args) { int mainNum1 = 1; int mainNum2 = 2; int ctr = 0; myMathFunction(mainNum1, mainNum2, ctr); } }
a) 2 4 8 16 32 End
b) 2 2 2 2 2
c) 2 4 8 16 32 64 End
d) 2 4 8 16 32
Computers and Technology
1 answer:
ycow [4]2 years ago
3 0

Answer:

The output of the program is:

2 4 8 16 32 64 End

Explanation:

See attachment for proper presentation of the program

The program uses recursion to determine its operations and outputs.

The function is defined as: myMathFunction(int a, int r, int counter)

It initially gets the following as its input from the main method

a= 1; r = 2; counter = 0

Its operation goes thus:

val = a*r; 1 * 2 = 2

Print val; Prints 2

if (counter > 4) { System.out.print("End"); } : Not true

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 2; r = 2; counter = 1

val = a*r; 2 * 2 = 4

Print val; Prints 4

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 4; r = 2; counter = 2

val = a*r; 4 * 2 = 8

Print val; Prints 8

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 8; r = 2; counter = 3

val = a*r; 8 * 2 = 16

Print val; Prints 16

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 16; r = 2; counter = 4

val = a*r; 16 * 2 = 32

Print val; Prints 32

else { myMathFunction(val, r, counter + 1); }: True

The value of counter is incremented by 1 and the function gets the following values:

a= 32; r = 2; counter = 5

val = a*r; 32 * 2 = 64

Print val; Prints 64

if (counter > 4) { System.out.print("End"); } : True

<em>This prints "End"</em>

So; the output of the program is:

2 4 8 16 32 64 End

You might be interested in
Why is musical notation important? What benefits do musicians and others receive from being able to write down and note aspects
madreJ [45]
Most importantly, musicians can share their works with others.  Other people can see their musical ideas and can try and perform them too.   Nuances such as tempo, dynamics (loud soft, sweet, "harsh", are just some examples) can be understood even if the composer is not present and there is no recording to listen to.
Financial benefits can be realized from the sale of sheet music, scoring the piece, arranging the piece for bands, orchestras, etc. Conductors can lead an entire musical ensemble through the piece. 
4 0
3 years ago
Write an application that displays appropriate prompts to the user and reads a person
vfiekz [6]

Answer:

The program to this question can be given as:

Program:

import java.util.*; //import package  

public class Person_detail //define class

{

public static void main(String ar[]) //define main function

{

String Name,hobby,dream_Job; //declare variable.

int age;

Scanner sc = new Scanner(System.in); //creating Scanner class object for user input.

System.out.print("Enter Your Name : "); //message  

name = sc.next(); //user input

System.out.print("Enter Your Age : ");

age = sc.nextInt();

System.out.print("Enter Your hobby: ");

hobby = sc.next();

System.out.print("Enter Your aim: ");

aim = sc.next();

//print values.

System.out.println("Hello, my name is "+name+" and I am "+age);

System.out.println("years old.My hobby is playing "+hobby+".");

System.out.println("I want to be a "+aim+" when I grow up!");

}

}

Output:

Hello, my name is XXX and I am 21

years old.My hobby is playing cricket .

I want to be a cricketer when I grow up!.

Explanation:

In the above program firstly we import the package for user input. Then we declare a class that is Person_detail. In this class, we declare the main function. In the main function, we declare a variable that is name, hobby, aim, and age. In these variable first 3 variables datatype is string and age variable data type in integer. Then we create a scanner class object and take input from the user and print it into a paragraph.

3 0
2 years ago
Assume that a gallon of paint covers about 350 square feet of wall space. Create an application with a main() method that prompt
Makovka662 [10]

Answer:

<em>C++</em>

#include <iostream>

#include <cmath>

using namespace std;

///////////////////////////////////////////////////////////////////////

int noOfGallons(int wallArea) {

   int gallon = 350;

   int gallon_price = 32.0;

   float total_price = 0.0;

   ///////////////////////////////////////////

   float noOfGallons = (float)wallArea/(float)gallon;

   printf("No of gallons needed %.2f", noOfGallons);

   cout<<endl;

   //////////////////////////////////////////

  total_price = noOfGallons*gallon_price;

   return round(total_price);

}

int wallArea(int length, int width, int height) {

   int wall_area = length*width;

   int total_price = noOfGallons(wall_area);

}

///////////////////////////////////////////////////////////////////////

int main() {

   int length, width, height;

   ///////////////////////////////////////////

   cout<<"Enter length: ";

   cin>>length;

   

   cout<<"Enter width: ";

   cin>>width;

   

   cout<<"Enter height: ";

   cin>>height;

   

   cout<<endl;

   ///////////////////////////////////////////

   int total_price = wallArea(length, width, height);

  cout<<"Total price: $"<<total_price;

   ///////////////////////////////////////////

   return 0;

}

5 0
2 years ago
Which loan type requires you to make loan payments while you’re attending school?
Levart [38]
<span>A:Unsubsidized federal loan</span>
7 0
3 years ago
Comments should
suter [353]

Answer:

Correct answer is:

communicate the purpose of the code that follows it.

Explanation:

Let have a look at each option

comment should give the reader the background of the programmer.

Comments are unable to do so.

Be written on every line

No, it is not need as comment are useful only to explain difficult or complex part of code.

communicate the purpose of the code that follows it.

yes, this option is true, as comments will give hints to programmer about the piece of code.

give information about how many hours it took to write the code

No, comments can answer it,

3 0
2 years ago
Read 2 more answers
Other questions:
  • In older systems, often the user interface mainly consisted of ____-control screens that allowed a user to send commands to the
    11·1 answer
  • Camera shock might happen if you do which of the following to your camera?
    6·2 answers
  • Data administration is a special organizational function that manages the policies and procedures through which data can be mana
    9·1 answer
  • What is the main storage location of a computer
    13·1 answer
  • Do you need to know javascript to learn python?
    8·1 answer
  • At the aquarium Grandma Simpson hugged the dolphin is that passive or active sentence​?
    6·1 answer
  • An element in an array is 4 bytes long and there are 10 elements in the array. How big is the array?
    6·2 answers
  • Robert works in a call center and receives a call from Kathy. Kathy says she can no longer access the online reporting applicati
    13·1 answer
  • Python code 100 Random Numbers (twice)
    9·1 answer
  • AI is not embraced everywhere in every industry because _______.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!