Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //(c) A+ Computer Science
- //www.apluscompsci.com
- //Name -
- import java.util.Arrays;
- public class TotalRow
- {
- public static int[] getRowTotals( int[][] m )
- {
- int[] rowTotals = new int[m.length];
- for(int r = 0; r < m.length; r++){
- int rowTotal = 0;
- for(int c = 0; c < m[r].length; c++){
- rowTotal += m[r][c];
- }
- rowTotals[r] = rowTotal;
- }
- return rowTotals;
- }
- public static void main(String[] args){
- int[][] f = {{1,2,3},{5,5,5,5}};
- System.out.println( Arrays.toString( getRowTotals( f ) ) );
- f = new int[][]{{1,2,3},{5},{1},{2,2}};
- System.out.println( Arrays.toString( getRowTotals( f ) ) );
- f = new int[][]{{1,2},{5,5},{5,5},{4,5,6,7},{123124,12312}};
- System.out.println( Arrays.toString( getRowTotals( f ) ) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement