Advertisement
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);
- int rows = scan.nextInt();
- int cols = scan.nextInt();
- int numbers[][] = new int[rows][cols];
- 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();
- }
- }
- Print(numbers);
- Sum(numbers);
- }
- 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();
- }
- }
- public static void Sum(int numbers [][]){
- int sum = 0;
- for (int i = 0; i < numbers.length; i++) {
- for (int j = 0; j < numbers.length; j++) {
- sum += numbers[i][j];
- }
- }
- System.out.print("Sum is :" + sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement