In Java, an array lets you store multiple values in a single variable. Super useful when you’re working with a list of items!
//Structure of arrays in java
int[] numbers = {10, 20, 30, 40};
//Accessing Elements
System.out.println(numbers[0]); // 10
System.out.println(numbers[2]); // 30
๐ฅ Array Properties
-
Fixed size (you can’t change its length)
-
Index starts at
0
-
numbers.length
gives you the number of elements
๐งช Challenge
Create an array of your 5 favorite numbers and print them all using a loop.
No comments:
Post a Comment