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

Questions 14 – 16 are based on the following code: public static void nPrint(Str

ID: 3828009 • Letter: Q

Question

Questions 14 – 16 are based on the following code:

public static void nPrint(String message, int n)

{

      while (n > 0)

      {

                System.out.print(message);

                n--;

      }

}

Flag this Question

Question 145 pts

The above code is an example of:

Flag this Question

Question 155 pts

What is the printout of the call:     nPrint("a", 4);

Flag this Question

Question 165 pts

What is the value of the identifier k after the following code fragment is evaluated?

                int k = 2;

                nPrint("A message", k+1);

A variable declaration

Explanation / Answer

The above code is an example of:
A method definition.
Its a method named nPrint which takes a String message, and an integer n as input, and a
void returning method.

What is the printout of the call: nPrint("a", 4);
The above method prints the input String message for n times.
Therefore, the output is: aaaa

What is the value of the identifier k after the following code fragment is evaluated?
int k = 2;
nPrint("A message", k+1);
This is a call by value method, and it will not modify the passed
parameter value, so what ever happens in the method, after the code fragement
k value will remain the same 2.