Run Code  | API  | Code Wall  | Users  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Write a program to sort the odd elements descending order and even elements in ascending order


            
                
            
 run  | edit  | history  | help 0

public class OddEvenArr { public static void main(String[] args) { int[] a= {13,2,4,15,12,10,5}; for (int i = 0; i < a.length; i+=2) { for (int j = i+2; j < a.length; j+=2) { int temp; if (a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } for (int i = 1; i < a.length; i+=2) { for (int j = i+2; j < a.length; j+=2) { int temp; if (a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } System.out.println(Arrays.toString(a)); } }

  by  iamNASH, 6 months ago




Please log in to post a comment.
Ff
3d