Arrays

Here are 20 problem statements covering various aspects of arrays in Java, ranging from basic to advanced:

  1. Initialize Array: Declare an array of integers named numbers with a size of 5 and initialize it with values {1, 2, 3, 4, 5}.

  2. Access Element: Print the third element of the array numbers.

  3. Modify Element: Change the value of the second element of the array numbers to 10.

  4. Array Length: Print the length of the array numbers.

  5. Sum of Elements: Calculate and print the sum of all elements in the array numbers.

  6. Average of Elements: Calculate and print the average of all elements in the array numbers.

  7. Find Maximum: Find and print the maximum element in the array numbers.

  8. Find Minimum: Find and print the minimum element in the array numbers.

  9. Copy Array: Create a new array copyNumbers and copy all elements from numbers to copyNumbers.

  10. Reverse Array: Reverse the elements of the array numbers in-place.

  11. Check Existence: Check if the value 6 exists in the array numbers. Print "Found" if it exists, otherwise print "Not found".

  12. Sort Array: Sort the elements of the array numbers in ascending order.

  13. Merge Arrays: Merge two arrays arr1 = {1, 2, 3} and arr2 = {4, 5, 6} into a new array mergedArray.

  14. Count Occurrences: Count and print the number of occurrences of a specific value (e.g., 3) in the array numbers.

  15. Remove Element: Remove the element at index 2 from the array numbers.

  16. Insert Element: Insert the value 7 at index 2 in the array numbers.

  17. Find Duplicate: Find and print all duplicate elements in the array numbers.

  18. Rotate Array: Rotate the elements of the array numbers to the left by one position.

  19. Find Missing Number: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

  20. Largest Subarray Sum: Given an array of integers, find the contiguous subarray with the largest sum.

These problems cover a wide range of concepts and operations related to arrays in Java, from basic operations like accessing and modifying elements to more advanced tasks like finding duplicates and computing subarray sums.

Last updated