Java Program to Find Maximum Difference Between Two Elements in an Array

This is a Java Program to Find 2 Elements in the Array such that Difference between them is Largest. Enter size of array and then enter all the elements of that array. Now we check for all possible difference between two elements and then select the elements whose difference is largest one. Here is the … Read more

advertisement

Java Program to Find the Largest Two Numbers in an Array

This is a Java Program to Find the Largest Two Numbers in a Given Array. Enter size of array and then enter all the elements of that array. Now we first sort the array in decreasing order using double for loops and hence get the first two elements as output. Here is the source code … Read more

advertisement

Java Program to Find Union and Intersection of Two Arrays

This is the Java Program to Find the Union and Intersection of 2 Arrays. Problem Description Given two arrays of integers, find and print the union and intersection of the arrays. Example: Array: [1,2,3,4,5] Array1: [5,3,6,7,9] Output: Union = [1,2,3,4,5,6,7,9] Intersection = [3,5] Problem Solution Create two sets called union and intersection. To find the … Read more

advertisement

Java Program to Insert an Element in an Array

This is a Java Program to Insert an Element in a Specified Position in a Given Array. Enter size of array and then enter all the elements of that array. Now enter the element you want to insert and position where you want to insert that element. We shift all the elements in the array … Read more

advertisement

Java Program to Print Even and Odd Numbers in an Array

This is a Java Program to Print the Odd & Even Numbers in an Array. Enter size of array and then enter all the elements of that array. Now using for loop and if codition we use to distinguish whether given integer in the array is odd or even. Here is the source code of … Read more

advertisement

Java Program to Find the kth Element in an Array

This is a Java Program to Print the kth Element in the Array. Enter size of array and then enter all the elements of that array. Now enter the position k at which you want to find element. Now we print the element at k-1 position in given array. Here is the source code of … Read more

advertisement

Java Program to Split an Array from Specified Position

This is a Java Program to Split an Array from Specified Position. Enter size of array and then enter all the elements of that array. Now enter the position from where you want to split. We first copy the elements from first position to that given position in secnd array and remaining elements in third … Read more

advertisement

Java Program to Find the Second Largest and Smallest Elements in an Array

This is a Java Program to Find the Second Largest & Smallest Elements in an Array. Enter size of array and then enter all the elements of that array. Now with the help of for loop and temp variable we sort the array in ascending order. Hence we get the first and second last element … Read more

advertisement

Java Program to Delete an Element from an Array

This is a Java Program to Delete the Specified Integer from an Array. Enter size of array and then enter all the elements of that array. Now enter the element you want to delete. We first find the location of that element and then shift the positions of all the elements after the element to … Read more

advertisement

Java Program to Separate Odd and Even Numbers from an Array

This is a Java Program to Put Even & Odd Elements of an Array in 2 Separate Arrays. Enter size of array and then enter all the elements of that array. Now with the help of for loop and if condition we check whether its odd or not and hence print it accordingly. Here is … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.