Question on reversing word of a sentnce

Question on reversing word of a sentnce

Write a function that accepts a sentence as a parameter, and returns the same with each of its words reversed. The returned sentence should have 1 blank space between each pair of words. Demonstrate the usage of this function from a main program. Example: Parameter: ?jack and jill went up a hill? Return Value: ?kcaj dna llij tnew pu a llih?

View Answers

February 9, 2011 at 10:58 AM

Java Reverse words of sentence

import java.util.*;
public class ReverseString{
    public static void main(String[]args){
        Scanner input=new Scanner(System.in);
        StringBuffer buffer=new StringBuffer();
        System.out.println("Enter string: ");
        String str=input.nextLine();
        StringTokenizer stk=new StringTokenizer(str);
        while(stk.hasMoreTokens()){
            String st=stk.nextToken();
           String reverse = new StringBuffer(st).reverse().toString();
           buffer.append(reverse);
           buffer.append(" ");
        }
        System.out.println("Reverse: " + buffer.toString());
    }
}









Related Tutorials/Questions & Answers:
Question on reversing word of a sentnce
Question on reversing word of a sentnce  Write a function that accepts a sentence as a parameter, and returns the same with each of its words reversed. The returned sentence should have 1 blank space between each pair of words
reversing a string
reversing a string  how to reverse a string without using string function   class ReverseString { public static void main(String[] args) { String str="Hello World"; String st[]=str.split
Advertisements
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
Question
Question   When there is an exception in my program how java runtime system handles
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
question
question  i have a project for search engine .i have a starting trouble , from where do i start project ,please help me.when i am given a key word to search ,which must return title,summary and url and i want to capture
question
question  Gud morning sir, I have asked u some question regarding jsp in saturaday for that i didnot find any answere in which u send me the some of the links.U have asked me the specify some details. There is a entity name
Question?
Question?  My question is how to: Add a menu bar to the program with a File menu. In the File menu, add a submenu (JMenuItem) called About. When the user clicks on the About menu item, display a JOptionPane message dialog
MicroSoft word
MicroSoft word  sir i want to develop an swing application like the microsoft word Document.can you help me pls
Reversing all root-to-leaf paths in a tree (JAVA) - Java Beginners
Reversing all root-to-leaf paths in a tree (JAVA)  A root-to-leaf path in a tree is defined to be a sequence of nodes starting from the root node... after reversing all root-to-leaf paths. For the following tree: root = 5
Java Word Processor
Java Word Processor  Problem: Design and implement a class called... of words (a hyphenated word is one word), o number of sentences (ends in a period), o number of questions (ends in a question mark), o number
NUMBER OF VOWELS IN A WORD
NUMBER OF VOWELS IN A WORD  WRITE A PROGRAM THAT WILL INPUT A WORD THEN IT WILL DETERMINE THE NUMBER OF VOWELS PRESENT IN THE INPUTTED WORD
Write String in Word document
Write String in Word document  How to read and write strings in word document
Compare two word file
Compare two word file  How to compare two word file using Java
Problem reading word file
Problem reading word file  Deepak you provide me code for extarcting equation from a word file and also to write in a word file.But when I again want to read preveously created word file(created by your code) it gives an error
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link.... It will be helpful for you to read data from word document
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link.... It will be helpful for you to read data from word document
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link.... It will be helpful for you to read data from word document
how to delete a letter in a word?
how to delete a letter in a word?  how to delete a letter in a word? for example if i enter= roseindia, i want to delete 's', then output= roeindia
finout longest word in sentence
finout longest word in sentence  write a program , how to find out the longest word in a sentence using java   Hi Friend, Try...; } } LongestWord(){ String word = ""; for(int i=0;i<stringArray.length;i++){ if(i==0
print word with max vowels
print word with max vowels  if suppose i hava entered a sentence and in that sentence i have to print a word which has maximum vowels in it.... i have tried it but i am not getting it...please help
com in ms word
com in ms word  how to use com object to fetch data from ms word and storing it into sql database
com in ms word
com in ms word  how to use com object to fetch data from ms word and storing it into sql database
java word counting - Java Beginners
java word counting  Hi I want a code in java that replaces a word...... but this will change all the occurrence even if its part of another word the run......Please try to explain your question properly...import java.util.Scanner;public
Display the data to MS word
the database(say im searching using an id) and should display it on the ms word , i want it to be in a good format. FOr example my word doc has to be Name... a word doc would help a lot!! thank you
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA word is present means
Scanning a word in a TEXT document......
Scanning a word in a TEXT document......  Hi Genius persons... I'm having many resumes in my FOLDER called HARISH in D:(colon) i want to scan... by searching the JAVA and .net words present in the files..if JAVA word is present means
String file in to word file in java
String file in to word file in java  How to convert a String format notepad file into Ms word file in java
from number to word
from number to word  i want to know weather there is any method that can be use in changing value from number to word. Example if i write ten thousand, it will automatically be written as 10000.   Java convert number
word program - Java Beginners
word program  HELLO MAM AND SIR I ASK YOUR HELP HOPE YOU GONNA HELP ME THANK YOU!!Design a program to search a word for letters that the user... within the word a letter that the user entered,change the value of the array
Word replacment - Java Beginners
Word replacment  Java code for the Word Replacement.Thnaks in Advance!  Hipublic class WordReplaced{ public static void main(String[] args){ String str1="the fat boy and his father"; String strreplace1="
String file in to word file in java
String file in to word file in java  how to convert a String format word file into Ms Word file using java? please can anyone of you help me
convert word document to pdf
convert word document to pdf  Hi, Could you please help me write a java code that converts the word docuemnt into PDF? I have to save the generated PDFs also. I got a code like the below, and i am unable to download the office
letter counting for the smallest word
and it works EXCEPT that it counts all of the letters not just the smallest word...(); int count=ch.length; System.out.println("Count of smallest word
store form data into word document
store form data into word document  i want form page data, ex username phone number.. to store it in a word document file
click a word and search it from a file
click a word and search it from a file  i want to link a word with a file and search it form the file by clicking it. what could the code for this process
ModuleNotFoundError: No module named 'painted-word'
ModuleNotFoundError: No module named 'painted-word'  Hi, My Python... 'painted-word' How to remove the ModuleNotFoundError: No module named 'painted-word' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Random-Word'
ModuleNotFoundError: No module named 'Random-Word'  Hi, My Python... 'Random-Word' How to remove the ModuleNotFoundError: No module named 'Random-Word' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'rpaframework-word'
ModuleNotFoundError: No module named 'rpaframework-word'  Hi, My... named 'rpaframework-word' How to remove the ModuleNotFoundError: No module named 'rpaframework-word' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'sensitive-word'
ModuleNotFoundError: No module named 'sensitive-word'  Hi, My... named 'sensitive-word' How to remove the ModuleNotFoundError: No module named 'sensitive-word' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'text-word'
ModuleNotFoundError: No module named 'text-word'  Hi, My Python... 'text-word' How to remove the ModuleNotFoundError: No module named 'text-word' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'text-word'
ModuleNotFoundError: No module named 'text-word'  Hi, My Python... 'text-word' How to remove the ModuleNotFoundError: No module named 'text-word' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'text-word'
ModuleNotFoundError: No module named 'text-word'  Hi, My Python... 'text-word' How to remove the ModuleNotFoundError: No module named 'text-word' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'word-count'
ModuleNotFoundError: No module named 'word-count'  Hi, My Python... 'word-count' How to remove the ModuleNotFoundError: No module named 'word... have to install padas library. You can install word-count python
ModuleNotFoundError: No module named 'word-count'
ModuleNotFoundError: No module named 'word-count'  Hi, My Python... 'word-count' How to remove the ModuleNotFoundError: No module named 'word... have to install padas library. You can install word-count python
ModuleNotFoundError: No module named 'word-counter'
ModuleNotFoundError: No module named 'word-counter'  Hi, My Python... 'word-counter' How to remove the ModuleNotFoundError: No module named 'word-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'word-embedder'
ModuleNotFoundError: No module named 'word-embedder'  Hi, My... 'word-embedder' How to remove the ModuleNotFoundError: No module named 'word-embedder' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'word_expanding'
ModuleNotFoundError: No module named 'word_expanding'  Hi, My... named 'word_expanding' How to remove the ModuleNotFoundError: No module named 'word_expanding' error? Thanks   Hi, In your python

Ads