Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("Please input element:");
- int row = scan.nextInt();
- System.out.println("Please input element:");
- int col = scan.nextInt();
- int numbers[][] = new int[row][col];
- for (int r = 0; r < numbers.length; r++) {
- for (int c = 0; c < numbers[r].length; c++) {
- System.out.println(" [ " + r + " ] [ " + c + " ] : ");
- numbers[r][c] = scan.nextInt();
- }
- }
- System.out.println();
- Print(numbers);
- System.out.println();
- for (int rows = 0;rows < numbers.length ; rows++) {
- int [] currentRow = numbers[rows];
- int sum = 0;
- int max = Integer.MIN_VALUE;
- int min = Integer.MAX_VALUE;
- for (int cols = 0; cols < currentRow.length; cols++) {
- int currentElement = currentRow[cols];
- if(max < currentElement){
- max = currentElement;
- }
- if(min > currentElement){
- min = currentElement;
- }
- sum += currentElement;
- }
- double average = (double) sum / (double) currentRow.length;
- String Average = String.format("%.2f" ,average);
- System.out.println();
- System.out.printf("Index: %d Sum: %d Max: %d Min: %d Average: %s" , rows , sum , max , min , Average);
- System.out.println();
- }
- }
- public static void Print(int numbers [][]) {
- for (int i = 0; i < numbers.length; i++) {
- for (int j = 0; j < numbers.length ; j++) {
- System.out.print(numbers[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment