FREE AP CSA Java Programming Basics Questions and Answers

0%

Which of the following are primitive data types in Java?

Please select 3 correct answers

Correct! Wrong!

Primitive data types in Java include int, boolean, char, double, float, long, short, and byte. String and ArrayList are reference types, not primitive data types.

What will the following code output?

Correct! Wrong!

The first if statement checks x > 5 and prints "A" since the condition is true.

The second if checks x < 20, which is true, so it prints "B". The else block is skipped because the if condition is true.

How many times will the following loop execute?

Correct! Wrong!

The loop runs as long as i < 5. Starting from i = 0 and incrementing by 1 each time, it will run for i = 0, 1, 2, 3, 4, which is 5 iterations.

What is the output of the following code?

Correct! Wrong!

The method substring(2) returns the substring starting from index 2 up to the end of the string. In "APCSA", characters start at index 0: A = index 0, P = index 1, C = index 2, so "CSA" is printed.

Which of the following correctly initializes an array in Java?

Please select 3 correct answers

Correct! Wrong!

A: Correctly initializes an array using the shorthand notation {1, 2, 3}. B: Creates an array of size 3 with default values (0 for int type). D: Explicitly declares an array with specified values using new int[]. C and E are invalid syntax.

Premium Tests $49/mo
FREE February-2025