fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. // Scanner sc=new Scanner(System.in);
  14. // int n=sc.nextInt();
  15. int[] ar={9,2,5,1,7};
  16. for(int i=0;i<ar.length;i++){
  17. System.out.println("array elements are :"+ar[i]);
  18. }
  19. int temp=0;
  20. for(int i=0;i<ar.length;i++){
  21. for(int j=1;j<i;j++){
  22. if(ar[j-1]>ar[j]){
  23. temp=ar[j-1];
  24. ar[j]=ar[j-1];
  25. ar[j]=temp;
  26. }
  27. System.out.println(temp);
  28.  
  29. }
  30.  
  31. }
  32. }
  33. }
Success #stdin #stdout 0.09s 33708KB
stdin
Standard input is empty
stdout
array elements are :9
array elements are :2
array elements are :5
array elements are :1
array elements are :7
9
9
9
9
9
9