This is a Java program that takes an integer array input from the user and prints out the unique elements of the array. Here is a brief explanation of the code:
import java.util.Scanner; public class Array_Unique_Element { static void getUnique(int a[], int n) { for (int i = 0; i < n; i++) { int j; for (j = 0; j < i; j++) if (a[i] == a[j]) break; if (i == j) System.out.print( a[i] + " "); } } public static void main (String[] args) { Scanner input =new Scanner(System.in); System.out.print("Enter the Array Limit :"); int l =input.nextInt(); int [] a =new int[l]; for(int i=0;i<l;i++) { System.out.printf("Element of a[%d] :",i); a[i]=input.nextInt(); } System.out.println("\nDisplay Array Unique Elements...\n"); getUnique(a, l); } }
Enter the Array Limit :5 Element of a[0] :10 Element of a[1] :20 Element of a[2] :40 Element of a[3] :10 Element of a[4] :20 Display Array Unique Elements... 10 20 40
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions