Data Types
Find the Error
Predict the Output
What's the Difference?
Basic Functions / Methods
100

Which data type is used to store a whole number?

int

100

Find the error: int age = "16";

"16" is a String, not an int.

100

What is printed?
int x = 8;
x = x + 2;
System.out.println(x);

10

100

What is the difference between int and double?  

int stores whole numbers; double stores decimal numbers.

100

Which method is used to print something to the console?

System.out.println()

200

Which data type would you use for true or false?

boolean

200

Find the error: boolean active = "true";

true should not be in quotation marks.

200

What is printed?
int x = 10;
int y = 3;
System.out.println(x / y);

3

200

What is the difference between String and char?

String stores a sequence of characters; char stores one character.

200

Write a condition that prints "Adult" if age is 18 or older.

if (age >= 18) { System.out.println("Adult"); }

300

What is the data type of 7L?

long

300

Find the error: double price = 19; int count = 2.5;

2.5 cannot be stored in an int.

300

What is printed?
int x = 15;
if (x > 10)
System.out.println("A");
else if (x > 5)
System.out.println("B");
else
System.out.println("C");

A

300

What is the difference between = and == in Java?

= assigns a value; == compares values.

300

Which class is commonly used to get user input from the keyboard?

Scanner

400

Which of these values can be stored in an int variable: 25, 3.14, "25", true?

25

400

int age = 17;
if (age >= 18);
System.out.println("Adult");
else
System.out.println("Minor");

There is an extra ; after the if condition.

400

What is printed?
int x = 10;
double y = 4.0;
System.out.println(x / y);

The closing ) and ; are missing from println().

400

What is the difference between if (x > 5) and if (x >= 5)?

The first excludes 5; the second includes 5.

400

Which Scanner method is used to read an integer?

nextInt()

500

Consider: int a = 10; double b = 3; double result = a / b; What is the data type of result, and approximately what value does it contain?

double, approximately 3.333...

500

int score = 75;
if (score >= 90)
System.out.println("A");
else if (score >= 80)
System.out.println("B");
else if (score >= 70);
System.out.println("C");

The ; after else if (score >= 70) ends the condition. Remove it.

500

What is printed?
int x = 7;
if (x > 5)
  if (x < 10)
    System.out.println("A");
  else
    System.out.println("B");
else
  System.out.println("C");

A

500

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

print() stays on the same line; println() moves to the next line.

500

How does the nextLine() method work, and how is it different from next() when reading input with a Scanner?

nextLine() reads the entire line of input, including spaces, until the user presses Enter. next() reads only the next token and stops at whitespace.

M
e
n
u