-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays.java
More file actions
29 lines (23 loc) · 936 Bytes
/
Arrays.java
File metadata and controls
29 lines (23 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
public class Arrays {
public static void main(String[] args) {
// ? Create object of the scanner class
Scanner sc = new Scanner(System.in);
// ? There are three ways to declare array in Java
// ! 1. Declaration and then memory allocation
int[] marks;
marks = new int[5]; // Declare and initialize an integer array with size 5
marks[0] = 92; // Assign values to each element
System.out.println("Marks at index 0 : " + marks[0]);
// ! 2. Declaration and memory allocation
int[] subject = new int[5];
subject[0] = 10;
subject[1] = 20;
subject[2] = 30;
System.out.println(subject[2]);
// ! 3. Dynamically size will be get by the java
int[] student = { 10, 20, 30 }; // Directly declaring and initializing an array
System.out.println(student[1]);
sc.close();
}
}