0% found this document useful (0 votes)
2 views

AP CS a Array Arraylist 2DArrays 20 Question Basic

The document outlines a set of 20 basic level questions for AP Computer Science A, focusing on arrays, ArrayLists, and 2D arrays. It is divided into three units: Unit 6 covers One-Dimensional Arrays with 7 questions, Unit 7 covers ArrayLists with 7 questions, and Unit 8 covers Two-Dimensional Arrays with 6 questions, each detailing methods, parameters, and example usages. Each unit provides specific tasks for manipulating data structures in Java.

Uploaded by

ovgutoprak2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

AP CS a Array Arraylist 2DArrays 20 Question Basic

The document outlines a set of 20 basic level questions for AP Computer Science A, focusing on arrays, ArrayLists, and 2D arrays. It is divided into three units: Unit 6 covers One-Dimensional Arrays with 7 questions, Unit 7 covers ArrayLists with 7 questions, and Unit 8 covers Two-Dimensional Arrays with 6 questions, each detailing methods, parameters, and example usages. Each unit provides specific tasks for manipulating data structures in Java.

Uploaded by

ovgutoprak2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

AP Computer Science A - Unit 6, 7, and 8 (Arrays, ArrayLists, 2D Arrays) - 20 Basic Level

Questions

Question Distribution:
7 questions - One-Dimensional Arrays (1D Arrays) → Written in the ArrayOperations class
7 questions - ArrayLists → Written in the ArrayListOperations class
6 questions - Two-Dimensional Arrays (2D Arrays) → Written in the MatrixOperations
class

Unit 6: 1D Arrays (ArrayOperations Class, 7 Questions)

Write a method that prints all elements of an int[] array to the console.
Class: ArrayOperations
Method Name: printArray
Parameters: int[] arr
Return Type: void

Example Usage:
int[] numbers = {1, 2, 3, 4, 5};
ArrayOperations.printArray(numbers);
// Output: 1 2 3 4 5

Write a method that returns the sum of all elements in a double[] array.
Class: ArrayOperations
Method Name: sumArray
Parameters: double[] arr
Return Type: double

Example Usage:
double[] values = {1.5, 2.5, 3.0};
System.out.println(ArrayOperations.sumArray(values));
// Output: 7.0

Write a method that returns the largest element in an int[] array.


Class: ArrayOperations
Method Name: findMax
Parameters: int[] arr
Return Type: int

Example Usage:
int[] numbers = {10, 25, 30, 5};
System.out.println(ArrayOperations.findMax(numbers));
// Output: 30
Write a method that counts how many times a given number appears in an int[] array.
Class: ArrayOperations
Method Name: countOccurrences
Parameters: int[] arr, int target
Return Type: int

Example Usage:
int[] numbers = {4, 5, 6, 5, 7, 5};
System.out.println(ArrayOperations.countOccurrences(numbers, 5));
// Output: 3

Write a method that prints all words in a String[] array in reverse order.
Class: ArrayOperations
Method Name: reversePrintArray
Parameters: String[] arr
Return Type: void

Example Usage:
String[] words = {"apple", "banana", "cherry"};
ArrayOperations.reversePrintArray(words);
// Output: cherry banana apple

Write a method that prints only the odd numbers in an int[] array.
Class: ArrayOperations
Method Name: printOddNumbers
Parameters: int[] arr
Return Type: void

Example Usage:
int[] numbers = {1, 2, 3, 4, 5};
ArrayOperations.printOddNumbers(numbers);
// Output: 1 3 5

Write a method that returns the sum of even numbers in a given int[] array.
Class: ArrayOperations
Method Name: sumEvenNumbers
Parameters: int[] arr
Return Type: int

Example Usage:
int[] numbers = {2, 3, 4, 5, 6};
System.out.println(ArrayOperations.sumEvenNumbers(numbers));
// Output: 12
Unit 7: ArrayLists (ArrayListOperations Class, 7 Questions)

Write a method that prints all elements in an ArrayList<Integer>.


Class: ArrayListOperations
Method Name: printList
Parameters: ArrayList<Integer> list
Return Type: void

Example Usage:
ArrayList<Integer> list = new ArrayList<>();
list.add(10); list.add(20); list.add(30);
ArrayListOperations.printList(list);
// Output: 10 20 30

Write a method that adds a word to an ArrayList<String>.


Class: ArrayListOperations
Method Name: addWord
Parameters: ArrayList<String> list, String word
Return Type: void

Example Usage:
ArrayList<String> words = new ArrayList<>();
words.add("Hello");
ArrayListOperations.addWord(words, "World");
System.out.println(words);
// Output: [Hello, World]

Write a method that returns the average of all elements in an ArrayList<Double>.


Class: ArrayListOperations
Method Name: calculateAverage
Parameters: ArrayList<Double> list
Return Type: double

Example Usage:
ArrayList<Double> list = new ArrayList<>();
list.add(2.0); list.add(4.0); list.add(6.0);
System.out.println(ArrayListOperations.calculateAverage(list));
// Output: 4.0

Write a method that checks if a given number is present in an ArrayList<Integer>.


Class: ArrayListOperations
Method Name: containsNumber
Parameters: ArrayList<Integer> list, int number
Return Type: boolean
Example Usage:
ArrayList<Integer> list = new ArrayList<>();
list.add(5); list.add(10); list.add(15);
System.out.println(ArrayListOperations.containsNumber(list, 10));
// Output: true

Write a method that returns the longest word in an ArrayList<String>.


Class: ArrayListOperations
Method Name: findLongestWord
Parameters: ArrayList<String> list
Return Type: String

Example Usage:
ArrayList<String> words = new ArrayList<>();
words.add("apple"); words.add("banana"); words.add("kiwi");
System.out.println(ArrayListOperations.findLongestWord(words));
// Output: banana

Write a method that removes all odd numbers from an ArrayList<Integer>.


Class: ArrayListOperations
Method Name: removeOddNumbers
Parameters: ArrayList<Integer> list
Return Type: void

Example Usage:
ArrayList<Integer> list = new ArrayList<>();
list.add(1); list.add(2); list.add(3); list.add(4);
ArrayListOperations.removeOddNumbers(list);
System.out.println(list);
// Output: [2, 4]

Write a method that finds the largest value in an ArrayList<Integer>.


Class: ArrayListOperations
Method Name: findMaxValue
Parameters: ArrayList<Integer> list
Return Type: int

Example Usage:
ArrayList<Integer> list = new ArrayList<>();
list.add(12); list.add(7); list.add(9); list.add(15);
System.out.println(ArrayListOperations.findMaxValue(list));
// Output: 15
Unit 8: 2D Arrays (MatrixOperations Class, 6 Questions)

Write a method that prints all elements in an int[][] matrix.


Class: MatrixOperations
Method Name: printMatrix
Parameters: int[][] matrix
Return Type: void

Example Usage:
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
MatrixOperations.printMatrix(matrix);
// Output:
// 1 2 3
// 4 5 6
// 7 8 9

Write a method that returns the sum of all elements in an int[][] matrix.
Class: MatrixOperations
Method Name: sumMatrix
Parameters: int[][] matrix
Return Type: int

Example Usage:
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
System.out.println(MatrixOperations.sumMatrix(matrix));
// Output: 45

Write a method that finds the largest value in an int[][] matrix.


Class: MatrixOperations
Method Name: findMaxValue
Parameters: int[][] matrix
Return Type: int

Example Usage:
int[][] matrix = {{3, 8, 1}, {7, 2, 6}, {5, 4, 9}};
System.out.println(MatrixOperations.findMaxValue(matrix));
// Output: 9

Write a method that prints the sum of each row in an int[][] matrix.
Class: MatrixOperations
Method Name: printRowSums
Parameters: int[][] matrix
Return Type: void
Example Usage:
int[][] matrix = {{1, 2, 3}, {4, 5, 6}};
MatrixOperations.printRowSums(matrix);
// Output:
// Row 0 sum: 6
// Row 1 sum: 15

Write a method that prints the elements along the diagonal of an int[][] matrix.
Class: MatrixOperations
Method Name: printDiagonal
Parameters: int[][] matrix
Return Type: void

Example Usage:
int[][] matrix = {{1, 0, 0}, {0, 2, 0}, {0, 0, 3}};
MatrixOperations.printDiagonal(matrix);
// Output: 1 2 3

Write a method that counts how many times a given number appears in an int[][]
matrix.
Class: MatrixOperations
Method Name: countOccurrences
Parameters: int[][] matrix, int target
Return Type: int

Example Usage:
int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 5}};
System.out.println(MatrixOperations.countOccurrences(matrix, 5));
// Output: 2

You might also like