-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveElement.java
More file actions
42 lines (36 loc) · 799 Bytes
/
RemoveElement.java
File metadata and controls
42 lines (36 loc) · 799 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
import java.util.Scanner;
public class RemoveElement {
public static int removeElement(int[] nums, int val)
{
int j=0;
int i=0;
while(i<nums.length)
{
if(nums[i]!=val)
{
nums[j]=nums[i];
j++;
}
i++;
}
return j;
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
System.out.println("Enter the array size");
int n;
n=s.nextInt();
int[] x=new int[n] ;
System.out.println("Enter the no.s");
for(int i=0;i<n;i++)
{
x[i]=s.nextInt();
}
System.out.println("Enter the value to be deleted");
int value=s.nextInt();
int result=removeElement(x,value);
System.out.println("The length of the array after deletion is "+result);
}
}