Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Second.Semester;
- public class functionsOfMatrix {
- public static void main(String[] args) {
- int[][] numbers = {
- {2, 5, 7, 8},
- {1, 3, 4, 9}
- };
- int min = Integer.MAX_VALUE;
- int max = 0;
- double sum = 0;
- double avg = 0;
- for (int row = 0; row < numbers.length; row++) {
- int[] currentRow = numbers[row];
- for (int cols = 0; cols < currentRow.length; cols++) {
- if (currentRow[cols] > max) {
- max = currentRow[cols];
- }
- if (currentRow[cols] < min) {
- min = currentRow[cols];
- }
- sum += currentRow[cols];
- }
- avg = sum / currentRow.length;
- System.out.println("The min of " + row + " row is: " + min);
- System.out.println("The max of " + row + " row is: " + max);
- System.out.printf("The sum of " + row + " row is: %.0f ", sum);
- System.out.println();
- System.out.print("The average is: ");
- System.out.printf("%.2f", avg);
- System.out.println();
- sum = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement