-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_18.java
More file actions
50 lines (33 loc) · 1.26 KB
/
Copy pathArray_18.java
File metadata and controls
50 lines (33 loc) · 1.26 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package Java_practice;
public class Array_18 {
public static void main(String[] args) {
// There are main 3 ways to Create and array
//1. Declaration and memory allocation together and then initialization ;
//Declaration and memory allocation
int[] marks=new int[5];
//initialization
marks[0]=34;
marks[1]=35;
marks[2]=56;
marks[3]=90;
marks[4]=67;
System.out.println("Marks at 4th position is In Array \t"+marks[4]);
System.out.println("************|Ends Here|**********");
//2. Declaration and Then memory allocation and then initialization ;
//Declaration and
int[] marks1;
//memory allocation
marks1=new int[5];
//initialization
marks1[0]=34;
marks1[1]=35;
marks1[2]=56;
marks1[3]=90;
marks1[4]=67;
System.out.println("Marks at 3rd position is In Array \t"+marks[3]);
System.out.println("************|Ends Here|**********");
//3 Declaration, memory allocation , initialization, Everything all together
int [] marks2 = {23,34,56,78,98};
System.out.println("Marks at 2nd position is In Array \t"+marks2[2]);
}
}