-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram40.java
More file actions
42 lines (30 loc) · 938 Bytes
/
Copy pathprogram40.java
File metadata and controls
42 lines (30 loc) · 938 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
34
35
36
37
38
39
40
41
42
// Deletion Array elements
import java.util.Scanner;
public class program40 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[10];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;
int n = 5;
System.out.print("Original Array: ");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
System.out.print("\nEnter Position to Delete (0 to " + (n - 1) + "): ");
int pos = sc.nextInt();
// Shift elements to the left
for (int i = pos; i < n - 1; i++) {
arr[i] = arr[i + 1];
}
n--;
System.out.print("Array After Deletion: ");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
sc.close();
}
}