There is string "aaa bbb cccc eee dddd ffff gggg sss qqq ertdfg"
We have to write a program to swap the alternate values in above string i.e. o/p has to be
"bbb aaa eee cccc ffff dddd sss gggg qqq ertdfg"
Printable View
There is string "aaa bbb cccc eee dddd ffff gggg sss qqq ertdfg"
We have to write a program to swap the alternate values in above string i.e. o/p has to be
"bbb aaa eee cccc ffff dddd sss gggg qqq ertdfg"
How do know - and how did you figure out - that swapping the elements of "aaa bbb cccc eee dddd ffff gggg sss qqq ertdfg" yields "bbb aaa eee cccc ffff dddd sss gggg qqq ertdfg"?
Before you write any code you should have a plan of attack: you should be conscious of the steps involved in how you solved the problem in this case, and be able to describe them. These steps - simple but comprehensive - will form the basis of your code.
Look through the String API documentation for methods that will help with splitting a string into its words. If you get stuck describe your approach. And post your code! Whether it works or not (it won't to begin with) it is the starting point.