Мне нужна помощь, передавая массив и имея возможность вернуть пустой массив - PullRequest
1 голос
/ 01 ноября 2019

Извините, я впервые использую этот сайт. Я пытаюсь вернуть нулевой массив. Надеюсь получить несколько указателей. Я сначала попытался вернуть null. Но затем изменил его, чтобы установить все значения массива на -1. Код указан ниже, я полагаю. Спасибо, любая помощь с благодарностью. Я получаю сообщение об ошибке «Этот метод должен возвращать результат типа int []» в Eclipse

public static int[] consecutive_Numbers(int[] integer_array)
    {
        boolean numbers_found = true;
        while (!numbers_found)
        {
            JOptionPane.showMessageDialog(null, "No consecutive numbers found");
            for(int a=0; a < integer_array.length; a++ )
            {
                integer_array[a] = -1;
            }
            return integer_array;
        }

        if(integer_array.length <= 0)
        {
            numbers_found = false;
        }

        else
        {
            for(int i = 5; i < integer_array.length; i++)
            {
                int counting = 1;
                do
                {
                    counting = counting + 1;
                }
                while(integer_array[i - counting] == integer_array[i + counting]);
                if(counting >= 4)
                {
                    int second_count = (counting * 2) + 1;
                    int[] int_array2 = new int[second_count];
                    int newIndex = i;
                    int m = i+counting;

                    for(int j = (second_count-1)/2; j > -1; j--)
                    {
                        int_array2[j] =  integer_array[newIndex];
                        newIndex--;
                    }
                    for(int k = second_count; k > (second_count-1)/2; k--)
                    {
                        int_array2[k] = integer_array[m];
                        m--;
                    }
                return int_array2; 
                }
            }
        for(int b=0; b < integer_array.length; b++ )
        {
            integer_array[b] = -1;
        }
        return integer_array;
        }
    }
}
...