电脑下载17zwd一起做网站,网站建网站建设设,wordpress添加新页面,做网站是做完给钱还是我正在一个项目中#xff0c;我必须读取文件并将内容输入2D数组。然后#xff0c;我必须对每一行#xff0c;每一列和矩阵的周长求和。到目前为止#xff0c;除外围功能外#xff0c;我一切正常。我正在尝试为两个外部列的顶行#xff0c;底行和中间创建单独的for循环。矩…我正在一个项目中我必须读取文件并将内容输入2D数组。然后我必须对每一行每一列和矩阵的周长求和。到目前为止除外围功能外我一切正常。我正在尝试为两个外部列的顶行底行和中间创建单独的for循环。矩阵文件如下所示1 2 3 42 4 6 82 4 6 83 2 3 4因此周长总计应为42。现在我可以成功地将第一行和最后一行添加为等于22。但是当我将列添加到总数中时我得到32。这是代码import java.util.*; // Scanner classimport java.io.*; // File classpublic class Lab10{static public void main( String [ ] args ) throws Exception{if ( args.length ! 1 ){System.out.println(Error -- usage is: java Lab10 matdataN.txt);System.exit( 0 );}//Requirement #1: first int value: # of rows, second int value: # of colsFile newFile new File(args[0]);Scanner in new Scanner(newFile);int numRows in.nextInt();int numCols in.nextInt();//Requirement #2: declare two-d array of intsint[][] matrix;matrix new int[numRows][numCols];//Requirement #3 4: read file one line at a time (nested for loops//and nextInt()) and printfor (int i 0; i numRows; i){for (int j 0; j numCols; j){matrix[i][j] in.nextInt();System.out.print(matrix[i][j] );}System.out.println();}//Requirement #5: traverse each row and sum the values and display the sumsint rowTotal 0;for (int i 0; i numRows; i){rowTotal 0;for (int j 0; j numCols; j){rowTotal matrix[i][j];}System.out.println(Sum for row rowTotal);}//Requirement #6: traverse each column and sum the values and display the sumsint colTotal 0;for (int i 0; i numRows; i){colTotal 0;for (int j 0; j numCols; j){colTotal matrix[j][i];}System.out.println(Sum for col colTotal);}//Requirement #7: traverse the perimeter and sum the values and display the sum//sum bottom row matrixint perTotal 0;for (int i (numRows-1); i numRows; i){perTotal 0;for (int j 0; j numCols; j){perTotal matrix[i][j];}}//sum top row matrixfor (int i 0; i numRows - (numRows-1); i){for (int j 0; j numCols; j){perTotal matrix[i][j];}System.out.println(Sum of perimeter perTotal);}// sum first col middlefor (int i 1; i (numRows-1); i){for (int j 0; j numCols - (numCols-1); j){perTotal matrix[j][i];}System.out.println(Sum perTotal);}// sum last col middlefor (int i 1; i (numRows-1); i){for (int j (numCols-1); j numCols; j){perTotal matrix[j][i];}System.out.println(perTotal);}}如果有人可以帮助我将第一列和最后一列的总和设为2 2和8 8我将非常感激。或者如果您有一种更好的方法来寻找周长。提前致谢