+ 1

How to print array [1,0,5,0,6,7,2,0] and result is 1,2,5,6,7,0,0,0 in java

array sorting

24th Aug 2018, 1:37 PM
Rajesh Shinde
Rajesh Shinde - avatar
5 Réponses
+ 2
First do a array.sort(); so everything will be sorted (with the 0 first), then, foreach values in your array, if this value at the index "i = 0" and the the value at index "i + 1 != 0" invert them using per exemple a temp var --> save value of index "i" in temp, set value of index i + 1 at index i and then put value of temp in the i + 1 index. I don't have time to code it right now (and no ide atm) but I can put the code here later. Try your best :)
24th Aug 2018, 2:15 PM
Sam Pache
Sam Pache - avatar
+ 2
java
24th Aug 2018, 1:41 PM
Rajesh Shinde
Rajesh Shinde - avatar
+ 1
help me
24th Aug 2018, 1:38 PM
Rajesh Shinde
Rajesh Shinde - avatar
+ 1
Which language?
24th Aug 2018, 1:40 PM
Just A Rather Ridiculously Long Username
+ 1
thanks i try
24th Aug 2018, 2:49 PM
Rajesh Shinde
Rajesh Shinde - avatar