如何使用for循环创建行?

时间:2014-03-07 23:21:10

标签: java php for-loop

public class Arraymini {

    public static void main(String [] args){
        int [] testArray1= {1,6,3,9,2};
        double [] testArray2= {2.3, 8.66, 6.5, -9.2};

        printArray(testArray1);
        printArray(testArray2);
    }

    public static void printArray(int []k){
        for(int i=0; i<k.length; i++){
        System.out.println(k[i]+" ");
        }
    }

    public static void printArray(double[]g){
        for(int i=0; i<g.length; i++){
            System.out.println(g[i]+" ");
        }
    }

}

是他们的一种方式我想改变它的for循环连续打印?????当我在eclipse中运行时,它会像以下一样直线打印:1                                                       6                                                       3                                                       2                                                       2.3                                                       8.66                                                       6.5                                                       -9.2 我需要它以空格分隔的行打印我该怎么做?

1 个答案:

答案 0 :(得分:0)

而不是printArrays方法,请执行:

System.out.println(Arrays.toString(testArray1));
System.out.println(Arrays.toString(testArray2));