Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package src;
- public class app {public static void main(String[] args)
- {
- int a[]={3,2,1,4,2,1,3,12,31,12};
- System.out.print("Before Sorting: ");
- for (int i=0;i<a.length; i++ ) {
- System.out.print(""+a[i]+"\t");
- }
- System.out.print ("\nAfter Sorting: ");
- for(int i=0;i<a.length;i++) {
- for(int j=i;j<a.length;j++) {
- if(a[i]>a[j]) {
- int temp=a[i];
- a[i]=a[j];
- a[j]=temp;
- }
- }
- }
- for(int i=0;i<a.length;i++) {
- System.out.print(" "+a[i]+"\t");
- }
- System.out.print("\nAfter removing duplicates: ");
- int b=0;
- a[b]=a[0];
- for(int i=0;i<a.length;i++) {
- if (a[b]!=a[i]) {
- b++;
- a[b]=a[i];
- }
- }
- for (int i=0;i<=b;i++ ) {
- System.out.print(" "+a[i]+"\t");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement