Click here to Skip to main content
15,917,702 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If Input:-
"My name is niroop."

Output should be:-

"My eman is poorin."


[additional info]

If user gives input "my name is niroop." with lot of spaces in between the words,it should take only one space between words.

every even word should be reveresed in a string.
In the end full stop should not be reveresed.

[/additional info]
Posted
Updated 26-Aug-15 0:41am
v3
Comments
Andy Lanng 26-Aug-15 5:46am    
what are the rules? Every other word? every noun and pronoun?
I get what your asking but a valid answer to this question would be:
if(System.console().readLine()=="My name is niroop.")
System.out.println("My eman is poorin.");

I assume the program should reverse all the words at even positions in the sentence.
Then you have to:
  • Extract the words at even positions (have a look at String.split[^] documentation).
  • Reverse every extracted words (see this Stack Overflow question: "Reverse a string in Java"[^]).
  • Use the original words at odd positions and reversed words to produce the output sentence.
 
Share this answer
 
v2
No,if user gives input"my name is niroop" with lot of spaces it will take spaces.
I have written the code and its running fine.

Ur logics are not correct,u should pratice more programs in java and think in a different way,that's my suggestion whoever is replying.

or write the code and show me.
 
Share this answer
 
Comments
CPallini 26-Aug-15 7:55am    
I have written the code and its running fine.
Good, congratulations.
So, no need to ask. :-)
Mohibur Rashid 28-Aug-15 5:09am    
Firstly, his logic is correct.
Secondly, logic has nothing to do with any specific programming language.
Thirdly, before you make a rubbish comment, why don't you read his profile?
Finally, you are rude. I would suggest you to correct your behavior. It will help you in the long run.

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