0% found this document useful (0 votes)
12 views21 pages

Java Array Operations Quiz

The document contains a series of programming questions related to arrays in Java, each with multiple-choice answers. The questions cover various array operations such as accessing elements, calculating sums, modifying values, and finding minimum or maximum values. Each question is designed to test the understanding of array manipulation and indexing in Java.

Uploaded by

S Mondal
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)
12 views21 pages

Java Array Operations Quiz

The document contains a series of programming questions related to arrays in Java, each with multiple-choice answers. The questions cover various array operations such as accessing elements, calculating sums, modifying values, and finding minimum or maximum values. Each question is designed to test the understanding of array manipulation and indexing in Java.

Uploaded by

S Mondal
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

Question 1

int arr[] = {3, 5, 7, 9};

[Link](arr[1] + arr[3]);

• a) 8

• b) 12

• c) 14

• d) 16

Question 2

int arr[] = {10, 20, 30, 40, 50};

[Link]([Link]);

• a) 4

• b) 5

• c) 6

• d) Compilation Error

Question 3

java

Copy code

int arr[] = {2, 4, 6, 8};

[Link](arr[[Link] - 2]);

• a) 6

• b) 8

• c) 4

• d) ArrayIndexOutOfBoundsException

Question 4

int arr[] = new int[5];

for (int i = 0; i < [Link]; i++) {

arr[i] = i + 1;

}
[Link](arr[3]);

• a) 2

• b) 3

• c) 4

• d) 5

Question 5

int arr[] = {5, 10, 15};

for (int i = 0; i < [Link]; i++) {

arr[i] = arr[i] * 2;

[Link](arr[2]);

• a) 15

• b) 20

• c) 30

• d) 40

Question 6

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

int sum = 0;

for (int i = 0; i < [Link]; i++) {

sum += arr[i];

[Link](sum);

• a) 3

• b) 5

• c) 6

• d) 10

Question 7

java

Copy code
int arr[] = {10, 20, 30, 40, 50};

[Link](arr[0] + arr[[Link] - 1]);

• a) 40

• b) 50

• c) 60

• d) 70

Question 8

java

Copy code

int arr[] = {2, 4, 6, 8, 10};

for (int i = 0; i < [Link]; i += 2) {

[Link](arr[i] + " ");

• a) 2 6 10

• b) 2 4 6

• c) 2 4 6 8 10

• d) 2 8

Question 9

java

Copy code

int arr[] = new int[4];

[Link](arr[3]);

• a) 0

• b) Compilation Error

• c) NullPointerException

• d) Undefined Behavior
Question 10

java

Copy code

int arr[] = {5, 10, 15, 20};

[Link](arr[1] * arr[3]);

• a) 50

• b) 100

• c) 150

• d) 200

Question 11

java

Copy code

int arr[] = {2, 4, 6, 8};

for (int i = [Link] - 1; i >= 0; i--) {

[Link](arr[i] + " ");

• a) 8 6 4 2

• b) 2 4 6 8

• c) Compilation Error

• d) ArrayIndexOutOfBoundsException

Question 12

java

Copy code

int arr[] = {3, 6, 9, 12};

[Link](arr[0] + arr[1] + arr[2] + arr[3]);

• a) 18

• b) 24

• c) 30

• d) 36
Question 13

java

Copy code

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

for (int i = 1; i < [Link]; i++) {

arr[i] += arr[i - 1];

[Link](arr[3]);

• a) 6

• b) 10

• c) 15

• d) 20

Question 14

java

Copy code

int arr[] = {1, 3, 5, 7};

int result = 0;

for (int i = 0; i < [Link]; i++) {

if (arr[i] % 2 == 0) {

result += arr[i];

[Link](result);

• a) 0

• b) 1

• c) 8

• d) Compilation Error
Question 15

java

Copy code

int arr[] = {2, 4, 6, 8};

int max = arr[0];

for (int i = 1; i < [Link]; i++) {

if (arr[i] > max) {

max = arr[i];

[Link](max);

• a) 2

• b) 6

• c) 8

• d) Compilation Error

Question 16

java

Copy code

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

[Link](arr[2] - arr[4]);

• a) -2

• b) -3

• c) 3

• d) 2

Question 17

java

Copy code

int arr[] = {5, 10, 15};

for (int i = 0; i < [Link]; i++) {

arr[i] = arr[i] / 5;
}

[Link](arr[1]);

• a) 1

• b) 2

• c) 3

• d) 10

Question 18

java

Copy code

int arr[] = {1, 3, 5, 7};

[Link](arr[0] * arr[[Link] - 1]);

• a) 7

• b) 5

• c) 3

• d) 7

Question 19

java

Copy code

int arr[] = {8, 6, 4, 2};

int count = 0;

for (int i = 0; i < [Link]; i++) {

if (arr[i] % 2 == 0) {

count++;

[Link](count);

• a) 2

• b) 3

• c) 4
• d) 5

Question 20

java

Copy code

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

int result = 1;

for (int i = 0; i < [Link]; i++) {

result *= arr[i];

[Link](result);

• a) 10

• b) 24

• c) 12

• d) 15

Question 21

java

Copy code

int arr[] = {9, 18, 27, 36};

[Link](arr[2] / arr[0]);

• a) 1

• b) 2

• c) 3

• d) 4

Question 22

java

Copy code

int arr[] = new int[5];

[Link](arr[[Link] - 1]);
• a) 0

• b) NullPointerException

• c) Compilation Error

• d) ArrayIndexOutOfBoundsException

Question 23

java

Copy code

int arr[] = {4, 8, 12, 16};

int sum = 0;

for (int i = 1; i < [Link]; i += 2) {

sum += arr[i];

[Link](sum);

• a) 8

• b) 16

• c) 24

• d) 28

Question 24

java

Copy code

int arr[] = {2, 4, 6, 8};

[Link](arr[0] + arr[2]);

• a) 8

• b) 10

• c) 12

• d) 14
Question 25

java

Copy code

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

for (int i = 0; i < [Link]; i++) {

if (i % 2 == 0) {

[Link](arr[i] + " ");

• a) 1 3

• b) 2 4

• c) 1 2

• d) 3 4

Question 26

java

Copy code

int arr[] = {5, 10, 15, 20};

[Link](arr[[Link] / 2]);

• a) 10

• b) 15

• c) 5

• d) ArrayIndexOutOfBoundsException

Question 27

java

Copy code

int arr[] = {10, 20, 30, 40};

[Link](arr[1] + arr[3]);

• a) 30

• b) 40
• c) 50

• d) 60

Question 28

java

Copy code

int arr[] = {3, 6, 9};

int sum = 0;

for (int i = 0; i < [Link]; i++) {

if (arr[i] % 3 == 0) {

sum += arr[i];

[Link](sum);

• a) 9

• b) 18

• c) 15

• d) 21

Question 29

java

Copy code

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

int result = arr[1] * arr[[Link] - 2];

[Link](result);

• a) 2

• b) 4

• c) 6

• d) 8
Question 30

java

Copy code

int arr[] = {7, 14, 21};

for (int i = 0; i < [Link]; i++) {

arr[i] /= 7;

[Link](arr[2]);

• a) 1

• b) 2

• c) 3

• d) 4

Question 31

java

Copy code

int arr[] = {2, 4, 6, 8, 10};

int result = 0;

for (int i = [Link] - 1; i >= 0; i -= 2) {

result += arr[i];

[Link](result);

• a) 10

• b) 18

• c) 16

• d) 8

Question 32

java

Copy code

int arr[] = {5, 10, 15};

int result = 0;
for (int i = 0; i < [Link]; i++) {

result += arr[i] % (i + 1);

[Link](result);

• a) 0

• b) 3

• c) 5

• d) 6

Question 33

java

Copy code

int arr[] = {2, 3, 5, 7};

for (int i = 1; i < [Link]; i++) {

arr[i] += arr[i - 1];

[Link](arr[3]);

• a) 7

• b) 12

• c) 17

• d) 19

Question 34

java

Copy code

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

int i = 0;

while (i < [Link]) {

arr[i] *= 2;

i++;

}
[Link](arr[2]);

• a) 2

• b) 4

• c) 6

• d) 8

Question 35

java

Copy code

int arr[] = {8, 6, 4, 2};

int sum = 0;

for (int i = 0; i < [Link]; i++) {

if (i % 2 == 0) {

sum -= arr[i];

} else {

sum += arr[i];

[Link](sum);

• a) -10

• b) -8

• c) 4

• d) 10

Question 36

java

Copy code

int arr[] = {3, 6, 9, 12};

int prod = 1;

for (int i = 0; i < [Link]; i++) {

if (arr[i] % 3 == 0) {
prod *= arr[i];

[Link](prod);

• a) 3

• b) 18

• c) 972

• d) 1944

Question 37

java

Copy code

int arr[] = {10, 20, 30, 40};

for (int i = 0; i < [Link] / 2; i++) {

int temp = arr[i];

arr[i] = arr[[Link] - 1 - i];

arr[[Link] - 1 - i] = temp;

[Link](arr[1]);

• a) 30

• b) 20

• c) 40

• d) 10

Question 38

java

Copy code

int arr[] = {5, 10, 15, 20, 25};

int sum = 0;

for (int i = 1; i < [Link] - 1; i++) {

sum += arr[i];
}

[Link](sum);

• a) 50

• b) 60

• c) 70

• d) 80

Question 39

java

Copy code

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

[Link](arr[(arr[2] + arr[3]) / 2]);

• a) 2

• b) 3

• c) 4

• d) ArrayIndexOutOfBoundsException

Question 40

java

Copy code

int arr[] = {3, 5, 7, 9};

int i = 0, sum = 0;

do {

sum += arr[i];

i++;

} while (i < [Link] - 1);

[Link](sum);

• a) 3

• b) 8

• c) 15

• d) 24
Question 41

java

Copy code

int arr[] = {6, 2, 8, 3};

int min = arr[0];

for (int i = 1; i < [Link]; i++) {

if (arr[i] < min) {

min = arr[i];

[Link](min);

• a) 6

• b) 2

• c) 3

• d) 8

Question 42

java

Copy code

int arr[] = {2, 4, 6, 8, 10};

int result = 0;

for (int i = 1; i < [Link]; i += 2) {

result += arr[i];

[Link](result);

• a) 12

• b) 18

• c) 16

• d) 8
Question 43

java

Copy code

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

for (int i = 0; i < [Link] / 2; i++) {

arr[i] += arr[[Link] - 1 - i];

[Link](arr[0]);

• a) 1

• b) 6

• c) 3

• d) 7

Question 44

java

Copy code

int arr[] = {4, 8, 12, 16};

int result = 0;

for (int i = 0; i < [Link]; i++) {

if (i % 2 != 0) {

result += arr[i];

[Link](result);

• a) 24

• b) 8

• c) 16

• d) 20

Question 45

java

Copy code
int arr[] = {2, 3, 5, 7, 11};

for (int i = 0; i < [Link]; i++) {

arr[i] = arr[[Link] - i - 1];

[Link](arr[2]);

• a) 3

• b) 5

• c) 11

• d) 7

Question 46

java

Copy code

int arr[] = {1, 4, 9, 16};

int i = 0, result = 1;

do {

result *= arr[i];

i += 2;

} while (i < [Link]);

[Link](result);

• a) 16

• b) 36

• c) 144

• d) 4

Question 47

java

Copy code

int arr[] = {10, 20, 30, 40};

int sum = 0;

for (int i = 0; i < [Link]; i++) {


if (i % 2 == 1) {

sum -= arr[i];

} else {

sum += arr[i];

[Link](sum);

• a) 0

• b) 40

• c) -20

• d) 20

Question 48

java

Copy code

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

for (int i = 1; i < [Link]; i++) {

arr[i] = arr[i - 1] % arr[i];

[Link](arr[5]);

• a) 1

• b) 0

• c) 9

• d) ArrayIndexOutOfBoundsException

Question 49

java

Copy code

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

int max = arr[0];

for (int i = 1; i < [Link]; i++) {


if (arr[i] > max && arr[i] % 2 == 1) {

max = arr[i];

[Link](max);

• a) 7

• b) 3

• c) 1

• d) 8

Question 50

java

Copy code

int arr[] = {5, 10, 15, 20, 25};

for (int i = 0; i < [Link]; i++) {

if (arr[i] % 10 == 0) {

arr[i] /= 2;

} else {

arr[i] *= 2;

[Link](arr[3]);

• a) 10

• b) 20

• c) 15

• d) 40

Common questions

Powered by AI

The code multiplies each element in the array by 2. After processing, the array becomes {2, 4, 6, 8} .

The method involves swapping elements from the beginning and end towards the center using a temporary variable. The loop runs until the middle of the array, ensuring each element is swapped correctly .

The do-while loop ensures at least one iteration, useful if starting conditions are unknown. However, since loop termination is tied to a known length condition, a for loop might be more predictable for accumulating values up to a defined point .

The loop iterates through each element of the array, checks if the element is even using the modulus operator (%), and if true, adds the element to the result variable. This process accumulates the sum of all even numbers in the array .

The loop selectively sums elements at odd indexes (or based on the step condition i += 2). It operates in linear time, O(n/2), simplifying to O(n), but iterates only half of the array elements, offering efficiency in reduction of operations .

This loop applies conditional transformations: elements divisible by 10 are halved, others doubled. It efficiently differentiates processing logic for elements based on a simple condition, showcasing dynamic transformation capabilities within linear complexity .

This loop overwrites elements destructively from index to index, not using a temporary variable for safe swaps. It essentially mirrors rather than reverses completely, failing because it overwrites immediately without maintaining the original state of replaced elements .

The loop uses the modulo operation to accumulate the remainder when each array element is divided by its index plus one. This adds clever handling of zero-based indices by preventing divide-by-zero and capturing non-divisible sums .

The code prints the value at index 3, which is within bounds for an array of size 4 (indexes 0 to 3). Since default initialization of int arrays sets all elements to 0, it will print '0' without an error .

The loop conditionally multiplies elements divisible by 3, aggregating a product result of such elements. This pattern is useful for scenarios demanding product accumulation under specific conditions, supporting applications in filtering-based aggregations .

You might also like