Advertisement
sergAccount

Untitled

Jun 26th, 2021
1,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 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.ex15;
  7.  
  8. /**
  9.  *
  10.  * @author student
  11.  */
  12. public class Main {
  13.    
  14.     public static void main(String[] args) {
  15.         // массивы (одномерные массивы)
  16.         // объявляем переменную типа массив (элементов типа int)
  17.         int[] array; // int[] - тип, array - имя переменной
  18.         // создаем массив с помощью ключевого слова new
  19.         array = new int[5]; // 3 - размерность массива (не больше 3 целых чисел)
  20.         //
  21.         int[] array1 = new int[10];
  22.         int[] array2 = new int[0]; // можно создать массив 0-ой длины
  23.         // для достпуа к элементу массива используется индекс элемента
  24.         int val1 = array[0]; // 0 - индекс первого элемента в массиве
  25.         System.out.println("val1=" + val1);
  26.         // получаем длину массива - используем св-во length
  27.         System.out.println("array.length=" + array.length);
  28.         // 2) - способ инициализации элементов массива
  29.         int[] arr = {10, 13, 56};
  30.         System.out.println("arr[0]=" + arr[0]);
  31.         System.out.println("arr[1]=" + arr[1]);
  32.         System.out.println("arr[2]=" + arr[2]);
  33.         System.out.println("arr.length=" + arr.length);
  34.     }    
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement