APCS WEEK 7 QUIZ

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Consider the following code segment. double x = (int) (5.5 - 2.5); double y = (int) 5.5 - 2.5; System.out.println(x - y); What is printed as a result of executing the code segment?

0.5

Consider the following method. public int getTheResult(int n) { int product = 1; for (int number = 1; number<n; number++) { if (number % 2 == 0) product *= number; } return product; } What value is returned as a result of the call getTheResult(8)?

48

Consider the following code segment. double x = 4.5; int y = (int) x * 2; System.out.print(y); What is printed as a result of executing the code segment?

8

Consider the following code segment. int a = 5; int b = 4; int c = 2; a *= 3; b += a; b /= c; System.out.print(b); What is printed when the code segment is executed?

9

Consider the following code segment. System.out.print("AP"); System.out.println(); System.out.println("CS"); System.out.print("A"); What is printed as a result of executing the code segment?

AP CS A

Which of the following expressions evaluate to 7 ? I. 9 + 10 % 12 II. (9 + 10) % 12 III.9 - 2 % 12

II and III

Consider the following code segment. System.out.print(*); // Line 1 System.out.print("*"); // Line 2 System.out.println(); // Line 3 System.out.println("*"); // Line 4 The code segment is intended to produce the following output, but may not work as intended. ** * Which line of code ,if any, causes an error?

Line 1

Consider the following code segment int w = 1; int x = w / 2; double y = 3; int z = (int) (x + y); Which of the following best describes the results of compiling the code segment?

The code segment compiles without erros.

The following code segment is intended to round val to the nearest integer and print the result. double val = -07; int roundedVal = (int) (val + 05); System.out.println(roundedVal); Which of the following best describes the behavior of the code segment?

The code segment does not work as intended because the expression (int) (val + 05) rounds to the nearest integer only when val is positive.

The code segment below is intended to calculate the circumference "c" of a circle with the diameter "d" of 1.5. The circumference of a circle is equal to its diameter times pi. /* missing declarations */ c = pi * d; Which of the following variable declarations are most appropriate to replace /* missing declarations*/ in this code segment?

final double pi = 3.14159; double d = 1.5; double c;

Directions: Select the choice that best fits each statement. The following question(s) refer to the following incomplete class declaration. Which of the following can be used to replace /*missing code*/ so that advance will correctly update the time?

hours=hours+minutes/60; minutes=minutes % 60;

Which of the following statements stores the value 3 in x ?

int x = 8 % 5;


संबंधित स्टडी सेट्स

Maternity and Pediatric Nursing/Chapter 38

View Set

Anatomy Chapter 4 - Abdominal Regions

View Set

Structure organisationelle Structure/classification/ fonctions

View Set

3421 Adults II - Emergency, Disaster, & Infection

View Set