Java Program To Reverse The Words In A Sentence
How to reverse words in a sentence without using split. Import java.util. Requirement is to only reverse the words in the sentence and not the.
Thank you, Mark and Jared. Mark- Yes, that is correct. I have used substring. When I assign a substring a number value like in the given example; it gives out an error. Sanyo Program Remote. Yes, another person used a loop for my problem. Here is the code for that: But, I fail to understand the code from 'words = line split (' ').'
Till the very end. Just does not make any sense to me. If any of you could explain it to me, ill appreciate it. Jared- What If I scan the words from the keyboard? How do I reverse any typed in sentence using the same formula?
Can you give an example? I am not able to grasp what you are saying.For my system: User inputs sentence. Scan sentence for number of spaces. Declare an array with an index equal to the number of spaces. Use the split function to split the sentence using ' ' as the delimiter and assign it to the array.
You know have an array where the first item is the first word, the second item is the second word and so on. So now, you know the size of the array so you compile a new string of the array values, starting with the last. You now have a string written backwards. I can do you a code example, but it would be in VB / VBA (can't remember where I used it last) and so I'm not sure if it would be any help to you. I think you have misunderstood me. The code has already been written. That is not my concern.
I want to understand what is going on in it. No, I am not too lazy to read up on it. I have read up on it. It's just the tone of the explanation in book is not in layman terms. Also, it takes time to gather all the info from the net.I can't devote all my time to one class.So, I thought it will be better if someone experienced can explain it in a simpler manner. Sorry for not being specific, Mark. Can you explain this line from the code: 'for (i = words.length - 1; i >= 0; i--)' what does the command above prompt the program to do?
What do '-1', 'i >=0', 'i --' refer to? Thank you for an elaborate explanation. Starting to make some sense now. Another question, if you don't mind. Can you explain these lines as well: lastchar= word.charAT (word.length ()-1); if (!Character.isLetter(lastchar)) word=lastchar + word.substring(0, word.length ()-1); reversed.append(word); if (i>0) reversed. Internet Kiosk Pro V6.1 Repack-planbdownload Free Software Programs Online. append (' ') In this line: 'lastchar= word.charAT (word.length ()-1);' the charAT assigned lastchar to 'i' right? 'if (!Character.isLetter(lastchar))' Means, when and if it reaches the laschar then do the following?