The document contains 22 problems involving arrays in Java including: finding if an array contains a value, getting the index of an element, removing elements, copying arrays, inserting elements, finding maximum/minimum values, reversing arrays, finding duplicates, common elements between arrays, removing duplicates, second largest/smallest elements, converting ArrayList to array, counting even/odd numbers, difference between largest and smallest values, averaging arrays excluding max and min, checking if sum of 10's is 30, checking for two specified elements, removing duplicates and returning new length, finding longest consecutive sequence, finding sum of two elements equal to target, and finding majority element.
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0 ratings0% found this document useful (0 votes)
25 views2 pages
Java 2
The document contains 22 problems involving arrays in Java including: finding if an array contains a value, getting the index of an element, removing elements, copying arrays, inserting elements, finding maximum/minimum values, reversing arrays, finding duplicates, common elements between arrays, removing duplicates, second largest/smallest elements, converting ArrayList to array, counting even/odd numbers, difference between largest and smallest values, averaging arrays excluding max and min, checking if sum of 10's is 30, checking for two specified elements, removing duplicates and returning new length, finding longest consecutive sequence, finding sum of two elements equal to target, and finding majority element.
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 2
1.
Write a Java program to test if an array contains
a specific value. 2. Write a Java program to find the index of an array element. 3. Write a Java program to remove a specific element from an array. 4. Write a Java program to copy an array by iterating the array. 5. Write a Java program to insert an element (specific position) into an array. 6. Write a Java program to find the maximum and minimum value of an array. 7. Write a Java program to reverse an array of integer values. 8. Write a Java program to find the duplicate values of an array of integer values. 9. Write a Java program to find the common elements between two arrays of integers. 10. Write a Java program to remove duplicate elements from an array. 11. Write a Java program to find the second largest element in an array. 12. Write a Java program to find the second smallest element in an array. 13. Write a Java program to convert an ArrayList to an array. 14. Write a Java program to find the number of even and odd integers in a given array of integers. 15. Write a Java program to get the difference between the largest and smallest values in an array of integers. The length of the array must be 1 and above 16. Write a Java program to compute the average value of an array of integers except the largest and smallest values. 17. Write a Java program to check if the sum of all the 10's in the array is exactly 30. Return false if the condition does not satisfy, otherwise true. 18. Write a Java program to check if an array of integers contains two specified elements 65 and 77. 19. Write a Java program to remove the duplicate elements of a given array and return the new length of the array. Sample array: [20, 20, 30, 40, 50, 50, 50] After removing the duplicate elements the program should return 4 as the new length of the array. 20. Write a Java program to find the length of the longest consecutive elements sequence from a given unsorted array of integers. Sample array: [49, 1, 3, 200, 2, 4, 70, 5] The longest consecutive elements sequence is [1, 2, 3, 4, 5], therefore the program will return its length 5. 21. Write a Java program to find the sum of the two elements of a given array which is equal to a given integer. Sample array: [1,2,4,5,6] Target value: 6. 22. Write a Java program to get the majority element from a given array of integers containing duplicates. Majority element: A majority element is an element that appears more than n/2 times where n is the size of the array.