Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.function.Supplier;
- public class trial {
- public static void main(String args[])
- {
- Scanner src=new Scanner(System.in);
- System.out.println("Enter the size of array");
- int n=src.nextInt();
- int arr[]=new int[n];
- int count=0;
- int count2=0;
- int js=0;
- List<Integer> list = new ArrayList<Integer>();
- List<Integer> listpro = new ArrayList<Integer>();
- System.out.println("Enter the numbers");
- for(int i=0;i<n;i++)
- {
- arr[i]=src.nextInt();
- js=arr[i];
- listpro.add(js);
- }
- System.out.println("The array is");
- for(int j=0;j<n;j++)
- {
- System.out.println(arr[j]);
- }
- for(int k=0;k<n;k++)
- {
- int var=arr[k];
- for(int m=k+1;m<n;m++)
- {
- if(var==arr[m])
- {
- count=1;
- }
- if(count==1)
- {
- list.add(var);
- count=0;
- }
- }
- }
- //List<int[]> list3=Arrays.asList(arr); //converting array to list
- //list3.removeAll(list);
- System.out.println("all numbers are "+listpro);
- System.out.println("The repeated numbers in the array are"+list);
- listpro.removeAll(list); // keeps only non dissimlar elements from two lists
- System.out.println("Non Repeated Elements in array are"+listpro);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement