-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDynamicArray.java
42 lines (37 loc) · 1016 Bytes
/
DynamicArray.java
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
package com.arrays;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class DynamicArray {
public static void main(String[] args) throws IOException {
int a[] = new int[6];
int size = 5;
int pos = 2;
int num = 10;
int len = 5;
//System.out.println(n);
for (int i = 0; i < size; i++) {
System.out.println("Enter The Array Elements : ");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
a[i] =n;
//System.out.println(a[i]);
}
System.out.println("***************");
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
System.out.println("Array Length : "+a.length);
for (int i = len-1; i >= pos-1; i--) {
a[i + 1] = a[i];
//System.out.println(a[i + 1]);
}
a[pos-1] = num;
//len++;
System.out.println("***************");
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}