🟡 Control Flow · Lesson 13
Arrays in Java
What is an Array?
An array stores multiple values of the same type in one variable, accessed by index (starting at 0).
Create and Loop
int[] marks = {88, 92, 79, 95};
int sum = 0;
for (int i = 0; i < marks.length; i++) {
sum += marks[i];
}
System.out.println("Total: " + sum);
System.out.println("First: " + marks[0]);Total: 354
First: 88
For-Each Loop
for (int m : marks) {
System.out.print(m + " ");
}88 92 79 95
Summary
- Arrays hold many same-type values; index starts at 0.
.lengthgives size; for-each loops easily over items.
Array क्या है?
Array एक ही type की कई values एक variable में रखता है, index से access (0 से शुरू)।
बनाएं और Loop करें
int[] marks = {88, 92, 79, 95};
int sum = 0;
for (int i = 0; i < marks.length; i++) {
sum += marks[i];
}
System.out.println("Total: " + sum);
System.out.println("First: " + marks[0]);Total: 354
First: 88
For-Each Loop
for (int m : marks) {
System.out.print(m + " ");
}88 92 79 95
सारांश
- Arrays एक ही type की कई values रखते हैं; index 0 से।
.lengthsize देता है; for-each items पर आसानी से loop करता है।
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.