fork download
  1. import java.util.*;
  2. class Solution
  3. {
  4. public static void main(String[]args)
  5. {
  6. Scanner s=new Scanner(System.in);
  7. int[] a={1,0,5,8,0,6,0,0,0};
  8. for(int i=0;i<a.length-1;i++)
  9. {
  10. for(int j=0;j<a.length-1;j++)
  11. {
  12. if(a[j]==0 &&a[j+1]!=0)
  13. {
  14. int temp=a[j];
  15. a[j]=a[j+1];
  16. a[j+1]=temp;
  17.  
  18. }
  19. }
  20. }
  21. for(int i=0;i<a.length;i++)
  22. {
  23. System.out.print(a[i]+" ");
  24. }
  25. }
  26. }
Success #stdin #stdout 0.19s 54924KB
stdin
Standard input is empty
stdout
1 5 8 6 0 0 0 0 0