zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcardStudy GuideStudy GuideQuestion BankQuestion Bank
GlossaryGlossary

Array Basics in AP Computer Science A

Question 1
Computer Science AAPConcept Practice
1 mark

What will be the output of the following code?

java
int[] arr = new int[3];
System.out.println(arr[0]);
Question 2
Computer Science AAPConcept Practice
1 mark

What happens if you try to compile and run the following code?

java
int[] nums = {1, 2, 3};
System.out.println(nums[3]);
Question 3
Computer Science AAPConcept Practice
1 mark

What is the output of the following code snippet?

java
int[] numbers = new int[5];
numbers[0] = 10;
numbers[4] = 20;
System.out.println(numbers[2] + numbers[4]);
Question 4
Computer Science AAPConcept Practice
1 mark

Consider the following code snippet. What is the output?

java
int[] arr = {1, 2, 3, 4, 5};
for (int i = 0; i < arr.length; i++) {
 for (int j = 0; j < arr.length; j++) {
 if (arr[i] + arr[j] == 6) {
 System.out.println(arr[i] + " " + arr[j]);
 }
 }
}
Question 5
Computer Science AAPConcept Practice
1 mark

What exception is thrown when you try to access an array element with an index that is out of bounds?

Question 6
Computer Science AAPConcept Practice
1 mark

How do you access the first element of an array named values in Java?

Question 7
Computer Science AAPConcept Practice
1 mark

Given the array double[] prices = {19.99, 24.50, 17.75};, how would you change the second element to 29.99?

Feedback stars icon

How are we doing?

Give us your feedback and let us know how we can improve

Question 8
Computer Science AAPConcept Practice
1 mark

What is the primary purpose of traversing an array?

Question 9
Computer Science AAPConcept Practice
1 mark

Given an array int[] values = {5, 10, 15, 20};, write a loop to add 2 to each element. Which of the following code snippets correctly does this?

Question 10
Computer Science AAPConcept Practice
1 mark

Which of the following is the correct way to declare an array of integers named numbers in Java?