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"
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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.