Advertisement
sergAccount

Untitled

Dec 6th, 2020
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 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 Main {
  13.     // массив в качестве параметра метода
  14.     public static void printArray(double[] arr){
  15.         for (int i = 0; i < arr.length; i++) {            
  16.             System.out.println(arr[i]);
  17.         }
  18.     }
  19.     public static double[] createArray(){
  20.         return null;
  21.     }
  22.     //    
  23.     public static void main(String[] args) {
  24.         // массивы
  25.         // 1) одномерные массивы
  26.         // объявление переменной типа массив
  27.         int[] array; // массив значений типа int
  28.         array = null;
  29.         array = new int[10]; // new - ключевое слово (для создания массива)
  30.         // 10 - размерность массива
  31.         int[] array2 = new int[2];
  32.         // доступ к элементу [] (в скобках указывается индекс элемента массива)
  33.         System.out.println("array2[0]=" + array2[0]);
  34.         int i = 0;
  35.         System.out.println("array2[0]=" + array2[i]);  
  36.         // вывод всех элементов массив array2 на экран
  37.         for (int j = 0; j < array2.length; j++) {            
  38.             System.out.println("array2[j]=" + array2[j]);
  39.         }        
  40.         System.out.println(" array2.length=" +  array2.length);
  41.         //
  42.         System.out.println("array2[2]=" + array2[2]);
  43.         System.out.println("OKKK!!!!!!!!!");
  44.         // заполнение массива по индексу
  45.         array2[0] = 10;
  46.         array2[1] = 2;
  47.         //array2[2] = 2;
  48.         System.out.println("array2[0]=" + array2[0]);
  49.        
  50.         String[] array3 = new String[2];
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement