Printing & Output
Variables & Input
Data Types
Operators (Arithmetic, Modulus, Unary)
Casting & Division
100

Which command prints text without moving to a new line?

System.out.print();

100

Write the correct declaration of an integer variable named score

int score;

100

Which primitive type would you use for true/false values?

boolean


100

What is the operator for remainder? (Name + Symbol)

Modulo and %

100

What kind of conversion happens when casting from a double to an int?

Narrowing Conversion

200

What is the difference between System.out.print and System.out.println?

System.out.print does not go to a new line after printing whereas System.out.println goes to a new line after printing.

200

If I want to input a decimal number but I want to save memory, which type should I use when declaring the variable?

float

200

Which of these is NOT a primitive type?

  • A) int

  • B) double

  • C) boolean

  • D) String

D) String

200

What is the output of this code?

int a = 10;

a++;

a *= 1;

System.out.println(a);

11
200

Which of these correctly casts a double d into an int?

  • A) int d = (int) 7.9;

  • B) double d = (int) 7.9;

  • C) int d = 7.9;

A) int d = (int) 7.9;

300

Which of these will cause a compile error?

  • A) System.out.println("Hello");

  • B) System.out.println(Hello);

  • C) System.out.print("Hello World");

System.out.println(Hello);

300

Assume Scanner scan = new Scanner(System.in). Which line correctly inputs a decimal?

scan.nextDouble();

300

What is the default data type for decimals in Java?

Double

300

What is (19 % 7) * 2 equal to?

6

300

What is the output of this code?
int x = 5;

int y = 2;

double z = x/y;

System.out.println(z);


2.0

400

What is the output of this code?

String x = "Hi";

String y = "Hello";

System.out.print(x + " or " + y);

400

Why should you always match Scanner methods to the correct data type (What error will this cause)?

An "incompatible types" error.


400

Which data type would you use for the answer to “What is your name?”

String

400

What is the output of this code?

int x = 6;

x += 4;

x /= 3;

x--;

System.out.println(x);

2

400

Write the Code:
Declare a variable x and initialize it to 3. Implicitly cast it to a double and store it into a new variable. Explicitly cast it back to an integer and store it into a new variable.

int x = 3;

double y = x;

int z = (int) y;

500

Fix the error in this line of code (2 fixes):
system.out.println(Hello World);

System.out.println("Hello World");

500

Write two separate lines of code: one to declare a Scanner variable, and one to initialize it.

Scanner scan;

scan = new Scanner(System.in);

500

Mr. Queen, my scanner class says "error: cannot find symbol" even though the declaration and initialization syntax is correct. What am I most likely missing from the top of my code?

import java.util.Scanner;
500

Declare and initialize an integer variable 10. Then, using a unary operator, increase it by 1. After that, find the remainder when dividing it by 2. If we then printed out the variable, what would be the output?

1

500

Explain the difference between widening and narrowing conversions in Java. Give an example of each using code.

Widening conversions are when you implicitly cast an integer to a double:
double var = 3;

Narrowing conversions are when you explicitly cast a double to an integer:
int x = 5;

double y = (int) x;