Advertisement
sergAccount

Untitled

Aug 16th, 2020
2,237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 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 com.mycompany.app12;
  7.  
  8. public class Test3 {    
  9.     //
  10.     public static void main(String[] args) {
  11.         // одномерный массив
  12.         int[] array = {1, 2, 3, 4};
  13.         // []
  14.         System.out.println("array[1]=" + array[1]);
  15.        
  16.         // двуменрный массив
  17.         // array2 - двуметный массив значений типа int
  18.         int[][] array2;
  19.         /*
  20.         1   2   3   4
  21.         5   6   7   8
  22.         */        
  23.         int[][] array3 = {
  24.             {1, 2, 3, 4},
  25.             {5, 6, 7, 8}
  26.         };
  27.         // вывод элементов массива на экран        
  28.         // длина массива (размерность массива)
  29.         System.out.println("array.len=" + array.length);
  30.         //
  31.         // длина двумерного массива
  32.         System.out.println("array3.len=" + array3.length);
  33.         System.out.println("Вывод элементов двумерного массива");
  34.         // вывод элементов двумерного массива в виде таблицы
  35.         for (int i = 0; i < array3.length; i++) {
  36.             System.out.println("i=" + i);
  37.             //System.out.println("");
  38.             int[] arr = array3[i];
  39.             System.out.println("arr.length=" + arr.length);
  40.             // вложенный цикл for - позволит получить все элементы одномерного массива
  41.             for (int j = 0; j < arr.length; j++) {
  42.                 System.out.println("array3[i][j]=" + array3[i][j]);                
  43.             }
  44.         }
  45.     }    
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement