请教java问题的答案

来源:百度知道 编辑:UC知道 时间:2024/05/26 10:40:19
请大家给我看看我的代码应该怎么改才能通,我才学完面向对象,请按我已学的知识帮我改错。

问题:请使用sort(double a[],int start,int end)可以把a指定的double型数组中从位置start到end-1位置的数按升序排序.写出使用上面方法的程序?

public class Rb
{
public static void main(String[] args)
{
double a[] = {2.177777,3.34444444,5.68888888,1.6222222222};
java.util.Arrays.sort(a,1,3);
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
}
}

}

public static void main(String[] args) throws Exception {
double[] a = sort(new double[]{5.0,4.0,3.0,2.0,1.0}, 1, 4);
for (double tmp : a) {
System.out.print(tmp + ",");
}

}

public static double[] sort(double a[],int start,int end) {
if (a == null || a.length == 0) return a;
if (start <= 0)
throw new IndexOutOfBoundsException("数组下限越界");
if (end > a.length)
throw new IndexOutOfBoundsException("数组上限越界");
for (int i = start; i < end - 1; i++) {
for (int j = i + 1; j < end; j++) {
if (a[i] > a[j]) {
a[i] = a[i] + a[j];<