Arrays
Here are 20 problem statements covering various aspects of arrays in Java, ranging from basic to advanced:
Initialize Array: Declare an array of integers named
numbers
with a size of 5 and initialize it with values {1, 2, 3, 4, 5}.Access Element: Print the third element of the array
numbers
.Modify Element: Change the value of the second element of the array
numbers
to 10.Array Length: Print the length of the array
numbers
.Sum of Elements: Calculate and print the sum of all elements in the array
numbers
.Average of Elements: Calculate and print the average of all elements in the array
numbers
.Find Maximum: Find and print the maximum element in the array
numbers
.Find Minimum: Find and print the minimum element in the array
numbers
.Copy Array: Create a new array
copyNumbers
and copy all elements fromnumbers
tocopyNumbers
.Reverse Array: Reverse the elements of the array
numbers
in-place.Check Existence: Check if the value 6 exists in the array
numbers
. Print "Found" if it exists, otherwise print "Not found".Sort Array: Sort the elements of the array
numbers
in ascending order.Merge Arrays: Merge two arrays
arr1 = {1, 2, 3}
andarr2 = {4, 5, 6}
into a new arraymergedArray
.Count Occurrences: Count and print the number of occurrences of a specific value (e.g., 3) in the array
numbers
.Remove Element: Remove the element at index 2 from the array
numbers
.Insert Element: Insert the value 7 at index 2 in the array
numbers
.Find Duplicate: Find and print all duplicate elements in the array
numbers
.Rotate Array: Rotate the elements of the array
numbers
to the left by one position.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.
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