Array Basics
Array Traversal
Array Operations
CIA
Bonus Points
100

What is the index of the first element in a Java array?

0

100

What will this code output:
int[] arr = {1, 2, 3}; 

System.out.println(arr[1]);

2

100

What is the value of arr[2] in int[] arr = {10, 20, 30, 40}?

30

100

CIA Triad stands for

Confidentiality

Integrity

Availability

100

This term refers to a set of instructions that a computer follows to perform a task, and it is a core concept in software development.

Programming

200

How do you declare an array of integers in Java?

int[] arr = new int[5];

200

Write a loop to print all elements of the array:

 int[] arr = {1, 2, 3, 4};

int[] arr = {1, 2, 3, 4};

for (int i = 0; i < arr.length; i++) {

    System.out.println(arr[i]);

}


200

How would you change the value of the first element in an array?

array[0] = value;

200

A company hashes their data files in order to monitor whether information has been tampered with.

Integrity

200

This control structure in Java evaluates a condition and executes one block of code if true, and another block if false.

IF statement

300

What is the size of the array int[] arr = {5, 10, 15, 20, 25}?  

5

300

Write the code to find the sum of elements in an array.

int[] arr = {1, 2, 3};

int[] arr = {1, 2, 3};

int sum = 0;

for (int i = 0; i < arr.length; i++) {

    sum += arr[i];

}

System.out.println(sum);


300

What is the result of this operation: arr[0] = arr[1] + arr[2] in int[] arr = {1, 2, 3}?

arr[0] becomes 5 (since 2 + 3 = 5).

300

A technology firm maintains an alternate site that is running 24/7, and operations can be moved to this location in the event of a major disaster.

Availability

300

This type of loop in Java will continue executing a block of code as long as a specified condition is true, often used when the number of iterations is not known in advance.

WHILE loop

400

What does arr[arr.length - 1] represent in an array?

last element in the array

400

Write a code to get the maximum element in an array.

    int max = arr[0];

    for (int i = 1; i < arr.length; i++) {

        if (arr[i] > max) {

            max = arr[i];

        }

    }


400

What happens when you try to access an index outside the bounds of an array?

It throws an ArrayIndexOutOfBoundsException.

400

Employees need to have key cards in order to enter their company offices.

Confidentiality

400

In Java, this special method is used to initialize an object when it is created, typically setting values for the object's attributes.

Constructor

500

Explain how array indexing works in Java.

Array indexing in Java starts at 0, meaning the first element is accessed with index 0.

500

Explain how nested loops work when traversing a 2D array.

The outer loop iterates over the rows, and the inner loop iterates over the elements (columns) in each row.

  • The outer loop runs for each row.
  • The inner loop runs for each column in the current row.
500

Write a code to double each element in an array.

for (int i = 0; i < arr.length; i++) {        arr[i] *= 2;    }

500

A hacker launched a DDoS attack which flooded a website with unwanted traffic from a number of computers.

Availability

500

This concept in Java allows a method to call itself, which can be especially useful in solving problems that can be broken down into smaller, similar subproblems.

Recursion