如何从单独的主java文件中调用此方法?

时间:2015-09-11 02:15:17

标签: java arrays methods

我需要从一个单独的java文件中调用main方法中的sortRows方法。如何拆分它以便在sortRows方法中完成测试并且在main方法中完成调用?下面的代码是相同的,但无论我将它们分开,我都会收到错误。

主要方法:

    Chapter8.chap8method();
    final int SIZE = 3;
    double[][] m = new double[SIZE][SIZE];
    double[] i1 = new double[] {0.15, 0.875, 0.375};
    System.out.print("1st array : ");
    Arrays.sort(i1);
    for(int index=0; index < i1.length ; index++)
    System.out.print("  " + i1[index]);


    double[] i2 = new double[]{0.55, 0.005,0.225};
    Arrays.sort(i2);
    System.out.print('\n' + "2nd array : ");
    for(int index=0; index < i2.length ; index++)
        System.out.print("  " + i2[index]);


    double[] i3 = new double[]{0.30, 0.12, 0.4};
    Arrays.sort(i3);
    System.out.print('\n' + "3nd array : ");
    for(int index=0; index < i3.length ; index++)
      System.out.print("  "  + i3[index]);

    ------------------------------------------------------

sortRows方法

    import java.util.Arrays;
    public class Chapter8 {
    public static void chap8method(){
    }

public static double[][] sortRows(double[][] m) {
    double[][] result = new double[m.length][m[0].length];
        //create an int array
        double[] i1 = new double[] {0.15, 0.875, 0.375};
        System.out.print("1st array : ");
        Arrays.sort(i1);
        for(int index=0; index < i1.length ; index++);



        double[] i2 = new double[]{0.55, 0.005,0.225};
        Arrays.sort(i2);
        System.out.print('\n' + "2nd array : ");
        for(int index=0; index < i2.length ; index++)
            System.out.print("  " + i2[index]);


        double[] i3 = new double[]{0.30, 0.12, 0.4};
        Arrays.sort(i3);
        System.out.print('\n' + "3nd array : ");
        for(int index=0; index < i3.length ; index++)
          System.out.print("  "  + i3[index]);

        return result;
      }
      }

0 个答案:

没有答案