Advertisement
sergAccount

Untitled

Dec 6th, 2020
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 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.ja8;
  7.  
  8. /**
  9.  *
  10.  * @author Admin
  11.  */
  12. public class Main3 {
  13.  
  14.     public static void main(String[] args) {
  15.         int[] arr = {10, 20};
  16.         // цикл for each
  17.         for (int v : arr) {
  18.             System.out.println(v);
  19.         }
  20.         // двумерные массивы
  21.         // 1) создание с использованием new
  22.         int[][] array = new int[2][2];
  23.         // 2) способ заполнения с использованием {}
  24.         int[][] array2 = {
  25.             {1, 2, 3},
  26.             {4, 5, 6}
  27.         };
  28.         // доступ к элементам - используем два индекса
  29.         System.out.println("array2[0][0]=" + array2[0][0]);
  30.         // получить кол-во массивов
  31.         System.out.println("array2.len=" + array2.length);
  32.         //
  33.         System.out.println("array2[0].len=" + array2[0].length);
  34.         System.out.println("array2[1].len=" + array2[1].length);
  35.         //
  36.         array2[0][0] = 777;
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement