Advertisement
sergAccount

Untitled

Mar 7th, 2021
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication4;
  7.  
  8. /**
  9.  *
  10.  * @author Admin
  11.  */
  12. public class JavaApplication4 {
  13.    
  14.     /*
  15.     Задача1
  16.     Создать двумерный массив значений типа double
  17.     Заполнить его числами  
  18.     Создать метод который находит сумму элементов
  19.     двумерного массива    
  20.     */    
  21.     public static double calcSum(double[][] arr){
  22.         double res = 0;
  23.         for (int i = 0; i < arr.length; i++) {
  24.             for (int j = 0; j < arr[i].length; j++) {
  25.                 res += arr[i][j];
  26.             }
  27.         }
  28.         return res;
  29.     }    
  30.     /*
  31.     Задача2
  32.     Создать двумерный массив значений типа int
  33.     Заполнить его числами  
  34.     Создать метод который находит сумму элементов
  35.     которые находятся на главной диагонали
  36.     */
  37.     public static int calcDiagSum(int[][] arr){
  38.         // ...
  39.         return 0;
  40.     }    
  41.  
  42.     /**
  43.      * @param args the command line arguments
  44.      */
  45.     public static void main(String[] args) {
  46.         // TODO code application logic here
  47.         double[][] arr = {
  48.             {1.0, 2.0},
  49.             {1.0, 2.0}
  50.         };
  51.         double result = calcSum(arr);
  52.         System.out.println("result=" + result);
  53.     }
  54.    
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement