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”

Answer Posted / vinay

public class Reversesentence {

public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter the sentence");
String str=s.nextLine();

String[] str2=str.split(" ");
int l=str2.length;
for(int i=0;i<l;i++) {
StringBuffer sb=new StringBuffer(str2[i]);
StringBuffer revstr = sb.reverse();
System.out.print(" "+revstr);
}


}

}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why doesnt this code work?

812


What is header file in c?

831


Why is c platform dependent?

803


What do you mean by a sequential access file?

813


What is keyword in c?

789


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

2227


Can a void pointer point to a function?

764


What is meant by gets in c?

809


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

1032


what are non standard function in c

1644


Can you mix old-style and new-style function syntax?

858


What is define directive?

856


Is swift based on c?

851


Explain what is the difference between a string and an array?

892


How do you view the path?

881