-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelet.java
More file actions
27 lines (27 loc) · 761 Bytes
/
Copy pathDelet.java
File metadata and controls
27 lines (27 loc) · 761 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
import java.util.*;
public class Delet{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int[] num = new int[n];
for(int i=0;i<n;i++){
num[i]=sc.nextInt();
}
System.out.println("Enter the Position of the element to Delete");
int d = sc.nextInt();
if(d<1||d>n){
System.out.println("Invalid position ");
return ;
}
int[] num1 = new int[n-1];
for(int i=0;i<d-1;i++){
num1[i]=num[i];
}
for(int i=d;i<n;i++){
num1[i-1]=num[i];
}
for(int i=0;i<n-1;i++){
System.out.print(num1[i]+" ");
}
}
}