美文网首页
Sort the odd(codewars-java)

Sort the odd(codewars-java)

作者: 坑货的自赎 | 来源:发表于2018-10-16 21:36 被阅读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;

      }

    }

    相关文章

      网友评论

          本文标题:Sort the odd(codewars-java)

          本文链接:https://www.haomeiwen.com/subject/xzjkzftx.html