Advertisement
MilaDimitrovaa

Задача за сумиране

Feb 28th, 2021
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scan = new Scanner(System.in);
  9.         int rows = scan.nextInt();
  10.         int cols = scan.nextInt();
  11.  
  12.  
  13.         int numbers[][] = new int[rows][cols];
  14.  
  15.  
  16.         for (int r = 0; r < numbers.length; r++) {
  17.             for (int c = 0; c < numbers[r].length; c++) {
  18.  
  19.  
  20.                 System.out.println(" [ " + r + " ] [ " + c + " ] : ");
  21.                 numbers[r][c] = scan.nextInt();
  22.             }
  23.         }
  24.         Print(numbers);
  25.         Sum(numbers);
  26.     }
  27.  
  28.     public static void Print(int numbers[][]) {
  29.         for (int i = 0; i < numbers.length; i++) {
  30.             for (int j = 0; j < numbers.length; j++) {
  31.                 System.out.print(numbers[i][j] + " ");
  32.  
  33.             }
  34.             System.out.println();
  35.         }
  36.     }
  37.     public static void Sum(int numbers [][]){
  38.  
  39.         int sum = 0;
  40.         for (int i = 0; i < numbers.length; i++) {
  41.             for (int j = 0; j < numbers.length; j++) {
  42.                 sum += numbers[i][j];
  43.             }
  44.         }
  45.         System.out.print("Sum is :" + sum);
  46.     }
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement