Scanner scan = new Scanner(System.in);

      double [][] DailyTemperature;

        double totalTracker = 0.0;
        String [] daysofweek = { "Monday ","Tuesday ","Wednsday ","Thursday","Friday ","Saturday ","Sunday "};

        DailyTemperature = new double[4][7];

        for ( int i = 0; i < DailyTemperature.length; i++ )
           for ( int j = 0; j < DailyTemperature[0].length; j++ )
            {
                System.out.print( "Enter " + daysofweek[j]+ "Temperature for week" + ( i + 1 ) + "\t");
                DailyTemperature[i][j] = scan.nextDouble( );

            }


所以这个问题只是确认2D数组是如何填充的,我的问题是在嵌套的for循环中,当i增加到1时,它保持为1直到j被计数7次然后增加1还是同时增加?

最佳答案

只是将它们视为堆栈。从外部循环开始,将其堆栈执行,然后进入内部,因此最深层的循环将位于顶部。您必须完成最顶层元素或最深层循环的工作,然后它才能在其下循环。这只是这种情况的一个比喻。希望你有主意。

08-16 18:13