-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplaceEl.java
More file actions
39 lines (32 loc) · 906 Bytes
/
ReplaceEl.java
File metadata and controls
39 lines (32 loc) · 906 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
import java.util.Scanner;
public class ReplaceEl {
public static void main(String args[])
{
int arr[]= new int[100];
int num,n,num1;
System.out.print("Enter the number of elements: ");
Scanner sc = new Scanner(System.in);
n= sc.nextInt();
System.out.print("Enter the elements: ");
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
System.out.print("Enter the elements to be Replaced: ");
num=sc.nextInt();
System.out.print("Enter the elements to Replace: ");
num1=sc.nextInt();
for(int i=0;i<n;i++)
{
if(num==arr[i])
{
arr[i]=num1;
}
}
System.out.print("The edited array: ");
for(int i=0;i<n;i++)
{
System.out.print(" "+arr[i]);
}
}
}