APCS-A Midterm Review

Ace your homework & exams now with Quizwiz!

What is the value of x after this code runs? int x = 5; x = 10; x = 4; 5 10 4 true

4

What is the value of myInteger after this line of code is executed? int myInteger = (int) 5.6; 6 5.6 5 9

5

What is the result of this expression? (int) (5 + 2 / 3 + 1) 5 6 6.67 7 0

6

Which of the following is not a primitive type? int double String boolean char

String

Which of the following statements is true about variables? The memory associated with a variable of a primitive type holds an actual primitive value. When a variable is declared final, its value can only be changed through a direct reassignment. A variable originally created as an int can be changed to store a double through casting. All of these choices are true

The memory associated with a variable of a primitive type holds an actual primitive value.

Which expression returns the 1's place of an integer x? x % 10 x / 10 x % 100 x + 1

x % 10

Refer to the following code segment: double myDouble = 1/4; System.out.println("1 / 4 = " + myDouble); The output of the code is: 1 / 4 = 0.0 The student wanted the output to be: 1 / 4 = 0.25 Which change to the first line of their code segment would get the student the answer that they wanted? int myDouble = 1/4; double myDouble = (double) 1/4; double myDouble = (int) 1/4; double myDouble = (int) (1.0/4.0);

double myDouble = (double) 1/4;

What is the proper syntax to declare and initialize a variable called temperature to have the value 70.4? int temperature = 70.4; double temperature = 70.4; temperature = 70.4; float temperature = 70.4; temperature = (double) 70.4

double temperature = 70.4;

What is the result of this expression? 4 + 8 * 3 / 4 + 5 % 2 5 6 12 11

11

What output will be produced by System.out.println("Hello"); System.out.println("Karel"); Hello Karel HelloKarel Hello Karel Error

Hello Karel


Related study sets

Managing Ppl/Org - Values and Attitudes

View Set

cross sectional male pelvis, scrotal & penile sonography

View Set

Gazdasagi szereplők, piacok, kereslet, kínálat

View Set