JAVA能不能帮我设计一个排序数组[4,3,78,68,98,1,4]的算法程序,谢谢各位大神

32、编写一个数组排序算法,将数组[4,3,78,68,98,1,4]进行从大到小排序输出。
33、编写一个算法返回上述数组中最大的数以及最大数的下标。
谢谢大神

public class ArraySort {

    public static void main(String[] args) {

        int array[] = new int[]{4, 3, 78, 68, 98, 1, 4};

        int oldArray[] = array.clone();

        for (int i = 0; i < array.length; i++) {

            for (int j = i + 1; j < array.length; j++) {

                if (array[i] < array[j]) {

                    int temp = array[i];

                    array[i] = array[j];

                    array[j] = temp;

                }

            }

        }

        System.out.println("排序结果:");

        for (int i : array) {

            System.out.print(i + "  ");

        }

        System.out.println();

        System.out.println("该数组中最大数为:" + array[0]);

        for (int i = 0; i < oldArray.length; i++) {

            if (array[0] == oldArray[i]) {

                System.out.println("最大数在原数组中的下标为:" + i);

            }

        }

    }

}

您好!上面是我写的代码。下图是执行结果。我把两道题写在一个程序代码里面了。

请确认。

来自:求助得到的回答
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜