SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package src;
  2.  
  3. public class app {public static void main(String[] args)
  4. {
  5.     int a[]={3,2,1,4,2,1,3,12,31,12};
  6.     System.out.print("Before Sorting: ");
  7.     for (int i=0;i<a.length; i++ ) {
  8.         System.out.print(""+a[i]+"\t");
  9.     }
  10.     System.out.print ("\nAfter Sorting: ");
  11.  
  12.     for(int i=0;i<a.length;i++) {
  13.         for(int j=i;j<a.length;j++) {
  14.             if(a[i]>a[j]) {
  15.                 int temp=a[i];
  16.                 a[i]=a[j];
  17.                 a[j]=temp;
  18.             }
  19.         }
  20.     }
  21.  
  22.     for(int i=0;i<a.length;i++) {
  23.         System.out.print(" "+a[i]+"\t");
  24.     }
  25.     System.out.print("\nAfter removing duplicates: ");
  26.     int b=0;
  27.     a[b]=a[0];
  28.     for(int i=0;i<a.length;i++) {
  29.         if (a[b]!=a[i]) {
  30.             b++;
  31.             a[b]=a[i];
  32.         }
  33.     }
  34.     for (int i=0;i<=b;i++ ) {
  35.         System.out.print(" "+a[i]+"\t");
  36.     }
  37. }
  38.  
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top