Advertisement
sergAccount

Untitled

Jul 3rd, 2021
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 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.ex16;
  7.  
  8. /**
  9.  *
  10.  * @author student
  11.  */
  12. public class Main {
  13.    
  14.     //
  15.     public static void main(String[] args) {
  16.         //
  17.         double[] arr = {1, 2};        
  18.         boolean[] arr1 = {true, false};
  19.         //
  20.         String[] array;
  21.         //
  22.         int[] arr2 = new int[4];  // new
  23.         String[] arr3 = new String[2];
  24.         //
  25.         for (int i = 0; i < arr2.length; i++) {
  26.             System.out.println("arr2[i]=" + arr2[i]);
  27.         }
  28.         //
  29.         for (int i = 0; i < arr3.length; i++) {            
  30.             System.out.println("arr3[i]=" + arr3[i]);            
  31.         }
  32.         // массив 0 - дины
  33.         int[] arr4 = new int[0];  // new
  34.         // что будет если мы выйдем за пределы массива (почему нужно использовать св-во length?)
  35.         //System.out.println("arr[2]=" + arr[2]); // 2 - недопустимы индекс!
  36.         System.out.println("OK!!!");
  37.         // заполнение массива определенными значениями
  38.         arr[0] = 10; // заполняем массив определенными значениями
  39.         arr[1] = 11;  
  40.         for (int i = 0; i < arr.length; i++) {
  41.             System.out.println("arr[i]=" + arr[i]);
  42.         }
  43.     }    
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement