Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can someone explain this code with comments I am supposed to dispay an array an add each columns and add each row An application uses
Can someone explain this code with comments I am supposed to dispay an array an add each columns and add each row An application uses a two-dimensional array declared as follows: int[][] days = new int[29][5]; a. Write code that sums each row in the array and displays the results. b. Write code that sums each column in the array and displays the results. class TwoDimensionalArrayDemo { public static void main( String[] arg ) { int[][] days = new int[29][5]; for (int i = 0; i < days.length; i++) { for (int j = 0; j < days[i].length; j++) { days[i][j] = i + j; } } for (int[] a : days) { for (int i : a) { System.out.print(i + "\t"); } System.out.println(" "); } System.out.println("column totals"); int totalRow = 0; for( int col = 0; col < 5; col++) { totalRow = 0; for( int row = 0; row < 29; row++) totalRow = totalRow + days [row][col]; System.out.println(totalRow); } System.out.println("row totals"); int totalCol; for( int row = 0; row < 29; row++) { totalCol = 0; for( int col = 0; col < 5; col++) totalCol = totalCol + days [row] [col]; System.out.println(totalCol); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started