Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
O/p
Enter the value 456239875
Enter the swapping value 4 9
After swapping
956234875
Posted
Comments
Sergey Alexandrovich Kryukov 2-Oct-13 0:50am    
First of all, an example is not a definition of the problem. You need to define the problem very accurately and formally, then, perhaps, it will be clear to yourself. Anyway, http://whathaveyoutried.com so far?
—SA

log each digit into an array, get the indices of the digits to be swapped from the array, and swap them using a temporary variable.
 
Share this answer
 
Like suggested use the string representation of the number, e.g.
Java
String s = String.valueOf(456239875);
s=s.replace('4','x');
s=s.replace('9','4');
s=s.replace('x','9');
int result = Integer.parseInt(s);
System.out.println(result);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900