Output Statements
Variables and Data Types
Expression and Assignment Statements
Compound Assignment Operators
Casting and Range of Variables
100

What code produces the intended output below?

Ready

Set

Go!


System.out.print("Ready\nSet\nGo!\n");

100

Which of the following is a valid identifier in Java?

123java

main

java1234

{abce

)whoot

java1234

100

What will be printed by the following code?

int x = 10;

int y = 20;

System.out.print( x / y - 20);

-20

100

What is printed when the code segment has been executed?

int z = 5;

z = z % 1;

z += 5;

z = z / z;

z /= z;

System.out.println(z);

1

100

What is printed as a result of executing the code segment?

double p = 5.6;

double n = 1.2;

System.out.print((int) (p + 0.5));

System.out.print((int) (n - 0.5));

60


200

What is printed as a result of executing the code segment?

System.out.println("A");

System.out.println("B");

System.out.print("C");

System.out.print("D");

A

B

CD

200

Which of the following is a GOOD identifier name

java1234

grade

student_grade

studentGrade

studentGrade

200

Which of the following can be used as a replacement for /* missing expression */ so that the code segment prints  31  ?

int x, y;

x = 3;

y = /* missing expression */;

x = 1 + 2 * y;

System.out.print(x);

System.out.println(y);

y = 0;
200

What is printed when the code segment has been executed?

int z = 0;

z++;

z *= 2;

z = z + z;

z -= 10;

System.out.println(z);

-2

200

What is printed as a result of executing the code segment?

double a = 11;

int b = (int) (a / 2);

double c = (double) b / 2;

System.out.print(b);

System.out.print(" ");

System.out.print(c);

5 2.5

300

What is printed as a result of executing the code segment?

System.out.print("Hello!");

System.out.println("How ");

System.out.print("are ");

System.out.print("you?");


Hello!How

are you?

300

Suppose you were developing a fitness tracker. Which of the following would be a variable your program may use?

int stepsTaken

double stepsTaken

float stepsTaken

boolean stepsTaken

int stepsTaken

300

What will be printed by the following code?

int x = 10;

int y = 20;

System.out.print( x / (y - 20) );



ArithmeticException or divide by zero syntax error

300

What is printed when the code segment has been executed?

int z = 0;

z++;

z += z;

z = z + 1;

z -= -1;

System.out.println(z);

4

300

What is printed as a result of executing the code segment?

double d = 0.25;

int i = 3;

double diff = d - i;

System.out.print((int)diff + 0.5);

-1.5

400

What is printed as a result of executing the code segment?

System.out.print("I");

System.out.println(" am ");

System.out.println("a     ");

System.out.print("troll!");

I am

a

troll!

400

What is the appropriate data type for a variable containing the value of the expression

/* data type */  isWeird = 10 < 25;

boolean

400

What do the following arithmetic expressions evaluate to?

4 / 5 % 3

4 / (7 % 4) 

4 - 1 / 2 - 2

0

1

2

400

What is printed when the code segment has been executed?

int z = 0;

z--;

z *= 2

z += 1;

z = z + 1;

z -= -1;

System.out.println(z);

-1

400

What does the code segment below print?

int num1 = 5;

int num2 = 10;

double ans = num1 / num2;

System.out.print(ans);

0

500

What is printed as a result of executing the code segment?

System.out.print("Is ");

System.out.print('this");

system.out.print(" real");

System.out.print("life");

Nothing, due to a syntax error

500
Who is the boolean data type named after?

George Boole

500

What is the value of x?

int a = 4;

int b = 3;

int c = 2;

int d = 1;

double x = a + b * c % d;


4.0

500

What is printed when the code segment has been executed?

int z = 15;

z /= 10;

z += z;

z --;

z %= 4;

System.out.println(z);

1

500

Consider the following code segment, which is intended to display 6.0. How would you fix it?


double fact1 = 1 / 2;

double fact2 = 3 * 4;

double product = fact1 * fact2;

System.out.println(product);


double fact1 = 1.0/2;

or

double fact1 = 1/2.0;

or

double fact1 = (double)1 / 2;

M
e
n
u