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

Assuming that the user inputs “Joe” at the prompt, what is the output of the fol

ID: 3668109 • Letter: A

Question

Assuming that the user inputs “Joe” at the prompt, what is the output of the following code snippet?

A.Joe, Good morning

Joe

C., Good morning

D.The code snippet does not compile because the += operator cannot be used in this context.

2.

Which of the following statements with comments is(are) valid?

I. int cnt = 0; /* Set count to 0

II. int cnt = 0; /* Set count to 0 */

III. int cnt = 0; // Set count to 0

II and III are valid

Only I is valid

Only III is valid

I and II are valid

2.What does the following statement sequence print?

A.Java is powerful

B.Java + is powerful

C.is powerful

D.Nothing; compile-time error

3.

What will be the value inside the variables x and y after the given set of assignments?

x = 20, y = 20

x = 10, y = 20

x = 20, y = 10

x = 40, y = 20

4.

Which one of the following statements displays the output as +00321.00?

A.System.out.printf("%09.00f", 321.0);

B.System.out.printf("+%09.2f", 321.0);

C.System.out.printf("%009,2f", 321.0);

D.System.out.printf("+9.2f", 321.0);

5.

What is the output of the following code snippet?

First: William

Last:

A.First: William

B.Last: lastname

C.Unpredictable output

D.Code will not compile

^.

What is wrong with the following code snippet?

A.The code snippet uses a variable that has not yet been initialized.

B.The code snippet attempts to assign a decimal value to an integer variable.

C.The code snippet attempts to assign an integer value to a decimal variable.

D.The code snippet uses a variable that has not been declared.

7.

What does the following statement sequence print?

A.Compile-time error

B.is powerful

C.Java is powerful

D.Java + is powerful

7.

What is the output of the following code snippet?

A.337.0

B.7.0

C.19.0

D.25.0

8.

Suppose that you time a program as a function of N and produce the following table.

        N   seconds

-------------------

     2048     0.000

     4096     0.001

     8192     0.004

    16384     0.014

    32768     0.051

    65536     0.194

   131072     0.741

   262144     2.821

   524288    10.719

1048576    40.915

2097152   155.502

4194304   591.610

8388608 2251.992

Estimate the order of growth of the running time as a function of N. Assume that the running time obeys a power law T(N) ~ a N^b. For your answer, enter the constant b. Your answer will be marked as correct if it is within 1% of the target answer - using two digits after the decimal separator, e.g., 2.34.

9.What is the order of growth of the worst case running time of the following code fragment as a function of N?

int sum = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < i; j++)
for (int k = 0; k < j; k++)
sum++;

A.N^3

B.N

C.N^2

D.NlgN

A.Joe, Good morning

B.

Joe

C., Good morning

D.The code snippet does not compile because the += operator cannot be used in this context.

Explanation / Answer

1. A.Joe, Good morning

2. II and III are valid

2. D.Nothing; compile-time error

3. x = 10, y = 20 (if we print x and y after the calcutaion the values would be x=5 and y= 5)

4. System.out.printf("+%09.2f", 321.0);

5. Code will not compile

6. The code snippet uses a variable that has not been declared.

7. Nothing; compile-time error

7. option B (7.0)

8.