Actually, that won't work, anyway. As if you replace all o with x then all x with o your string will consist of nothing but o
Step 1: get string
Step 2: replace x with z
Step 3: replace o with x
Step 4: replace z with o
Why do you feel the need to do it in one?
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,484
Solved Threads: 494
Skill Endorsements: 16
Even at the pseudocode level that's not going to work:
firstStep = console.nextLine(); eg "ooxxx"
secondStep = firstStep.replaceAll(o, x); "xxxxx"
thirdStep = thirdStep.replace(x, o); "ooooo"
System.out.println(thirdStep); "ooooo"
This needs an extra step:
replace all the o with some temp char
replace all the x with o
replace all the temp char with x
JamesCherrill
... trying to help
8,497 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29
Even at the pseudocode level that's not going to work:
firstStep = console.nextLine(); eg "ooxxx"
secondStep = firstStep.replaceAll(o, x); "xxxxx"
thirdStep = thirdStep.replace(x, o); "ooooo"
System.out.println(thirdStep); "ooooo"
This needs an extra step:
replace all the o with some temp char
replace all the x with o
replace all the temp char with x
Too slow! ;-)
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,484
Solved Threads: 494
Skill Endorsements: 16
Question Answered as of 2 Years Ago by
masijade,
rapture,
JamesCherrill
and 1 other