Загрузка...

Task 8 Part 1 Array Intro; declaration, initialization, simple array program by BeeHab

Task 8 - Part 1 : Array introduction Today’s goals: Array example class 1- Definition of an array: An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. Arrays are index based. 2- Declaration of an array ⇒ Declare an array of integers int [ ] anArray; 3- INITIALIZE THE ARRAY: Allocate memory of 10 integers. anArray = new int[10]; Or you can just write steps 2 & 3in one line: int [ ] anArray = new int[10]; 4- Create a program: ArrayExample with an array of integers. Element at index 0: 10 Element at index 1: 20 Element at index 2: 30 Element at index 3: 40 Element at index 4: 50 Element at index 5: 60 Element at index 6: 70 Element at index 7: 80 Element at index 8: 90 Element at index 9: 100 5- Validate the output. NEXT UP; let's see if you can figure out the following steps below: Shortcut syntax of the Array Initialization 1- int[ ] row, col, rowsCols[ ] ⇒ Break this down? 2- Clone method ? 3- Add an extra element in an array? 4- Shortcut Syntax of the array 5- Unchecked Exception??? Stay Tuned to BeeHab, It's in my DNA presents Java Learning Series 1 =====================SOURCE CODE===================== import java.util.Arrays; public class Task8_Array_Intro { static final int SIZE = 10; public static void main(String[] args) { // Declaration int [] anArray; int [] anArray2; // Initialize the array and Assign 10 integers anArray = new int[SIZE]; // write simple program that stores 10 integers // 0 1 2 3 4 5 6 7 8 9 // each index number show where elements added. anArray[0] = 10; anArray[1] = 20; anArray[2] = 30; anArray[3] = 40; anArray[4] = 50; anArray[5] = 60; anArray[6] = 70; anArray[7] = 80; anArray[8] = 90; anArray[9] = 100; String index0 = "Index 0= "+ anArray[0] + " " + "Index 3= " + anArray[3] + " " + "Index 6= " + anArray[6]; System.out.println(index0); System.out.println("Index 1= "+ anArray[1] + " " + "Index 4= "+ anArray[4] + " " + "Index 7= "+ anArray[7]); System.out.println("Index 2= "+ anArray[2] + " " + "Index 5= "+ anArray[5] + " " + "Index 8= "+ anArray[8]); System.out.println(" "+" Index 9= "+ anArray[9]); } } =====================SOURCE CODE=====================

Видео Task 8 Part 1 Array Intro; declaration, initialization, simple array program by BeeHab автора Java МастерПлан
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки