Advertisement
sergAccount

Untitled

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