Sort the odd(codewars-java)
2018-10-16 本文已影响0人
坑货的自赎
You have an array of numbers.
Your task is to sort ascending odd numbers but even numbers must be on their places.
Zero isn't an odd number and you don't need to move it. If you have an empty array, you need to return it.
public class Kata {
public static int[] sortArray(int[] array) {
int min=0;
for(int i =0;i<array.length;i++){
if(array[i]%2==0){
}else {
for(int j=i;j<array.length;j++){
if(array[j]%2==0){
}else{
if(array[i]>array[j]){
min=array[j];
array[j]=array[i];
array[i]=min;
}
}
}
}
return array;
}
}