-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeletion.java
More file actions
62 lines (36 loc) · 1.14 KB
/
Deletion.java
File metadata and controls
62 lines (36 loc) · 1.14 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
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.Scanner;
class Deletion {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of the array :");
int sizeOfArray=sc.nextInt();
System.out.println("Enter the array :");
int arr[]=new int[sizeOfArray];
for(int i=0;i<sizeOfArray;i++){
int x=sc.nextInt();
arr[i]=x;
}
System.out.println("Enter the delete element :");
int element=sc.nextInt();
delision(arr, sizeOfArray, element);
System.out.println("Modified Array :");
for(int i=0;i<sizeOfArray-1;i++){
System.out.println(arr[i]+" ");
}
}
public static void delision(int ar[],int n,int ele){
int index=-1;
for(int i=0;i<n;i++){
if(ar[i]==ele){
index=i;
break;
}
}
if(index==-1){
System.out.println("Not present");
}
for(int j=index;j<n-1;j++){
ar[j]=ar[j+1];
}
}
}