-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterchange.java
46 lines (45 loc) · 1.04 KB
/
interchange.java
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
import java.util.*;
class interchange
{
void main()
{
Scanner ob=new Scanner(System.in);
int a[]=new int [5];
int m,n,s,c,i,first,last,d;
System.out.println("Enter 5 elements in an array");
for(i=0;i<5;i++)
{
a[i]=ob.nextInt();
}
for(i=0;i<5;i++)
{
m=n=a[i];
s=0;
c=0;
first=0;
last=a[i]%10;
while(n!=0)
{
first=n%10;
n=n/10;
}
while(m!=0)
{
d=m%10;
if(d==first)
s=s+(int)Math.pow(10,c++)*last;
else if(d==last)
s=s+(int)Math.pow(10,c++)*first;
else
s=s+(int)Math.pow(10,c++)*d;
m=m/10;
}
a[i]=s;
}
System.out.println("UPDATED ARRAY IS");
for(i=0;i<5;i++)
{
System.out.println(a[i]+" ");
}
}
}