0% found this document useful (0 votes)
2 views20 pages

Understanding Arrays in Java

In Java, an array is an object that holds a fixed number of elements of the same data type, allowing for efficient storage and access of multiple values under a single variable name. Arrays simplify the management of large datasets, such as student marks, by enabling access through indices rather than creating numerous individual variables. This makes it easier to perform operations like looping and calculations on the stored data.

Uploaded by

mrarzoo143
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views20 pages

Understanding Arrays in Java

In Java, an array is an object that holds a fixed number of elements of the same data type, allowing for efficient storage and access of multiple values under a single variable name. Arrays simplify the management of large datasets, such as student marks, by enabling access through indices rather than creating numerous individual variables. This makes it easier to perform operations like looping and calculations on the stored data.

Uploaded by

mrarzoo143
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Arrays in Java

Introduction

• In Java, array is an object that stores a fixed number of elements of


the same data type.
• It stores multiple elements under a single variable name.
• Syntax :
• int[] marks = {88, 74, 91, 82, 68, 94};
Why we need arrays ?
• Suppose we have 6 students and we want to store their marks:
• int marks1 = 88;
• int marks2 = 74;
• int marks3 = 91;
• int marks4 = 82;
• int marks5 = 68;
• int marks6 = 94;
• This works fine for a few students, but imagine we have 100 or 1000
students. Creating so many variables would be difficult and messy.
• Solution: Arrays allow us to store all student's marks in a single variable:
• int[] marks = {88, 74, 91, 82, 68, 94};
• Now, we can access any student's mark using an index, loop through the
marks, and perform calculations easily.

You might also like