Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import java.io.* ;
  2.  
  3. class ColumnSums
  4. {
  5.  
  6. public static void main ( String[] args ) throws IOException
  7. {
  8. int[][] data = { {3, 2, 5},
  9. {1, 4, 4, 8, 13},
  10. {9, 1, 0, 2},
  11. {0, 2, 6, 3, -1, -8} };
  12.  
  13. // declare the sum
  14. int sum;
  15.  
  16. // compute the sums for each row
  17. for ( int col=0; col < 6; col++)
  18. {
  19. sum = 0;
  20. // compute the sum for this row
  21. for ( int row=0; row < data.length; row++)
  22. {
  23. if (data[row].length > col)
  24. sum = data[row][col] + sum;
  25. }
  26.  
  27. // write the sum for this row
  28. System.out.println("Columm " + col + " = " + sum);
  29. }
  30.  
  31. System.out.println();
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement