Tuesday, 22 April 2025

Introduction to Java Arrays

 

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

๐Ÿš€ Top 3 Java Projects Every Beginner Should Build (With Code Ideas)

 Tired of just printing "Hello World"? It’s time to build something real. ๐Ÿ’ป If you're learning Java and want to stand out, ...