-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathOne_Dimension_Array.java
More file actions
33 lines (30 loc) · 870 Bytes
/
One_Dimension_Array.java
File metadata and controls
33 lines (30 loc) · 870 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
30
31
32
33
package Arrays;
import java.util.Arrays;
public class One_Dimension_Array {
public static void main(String[] args) {
// Create an Array
int[] arr;
arr = new int[5];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5;
System.out.println(Arrays.toString(arr));
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
insertArray(arr, 4, 7);
System.out.println(Arrays.toString(arr));
}
// Insert into Array
public static void insertArray(int[] array, int location, int value){
try{
array[location] = value;
}catch (ArrayIndexOutOfBoundsException e){
System.out.println("Error: Invalid index!");
e.printStackTrace();
}
}
// Accessing Array Element
}