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
Why doesnt this code work?
What is header file in c?
Why is c platform dependent?
What do you mean by a sequential access file?
What is keyword in c?
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]
Can a void pointer point to a function?
What is meant by gets in c?
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
what are non standard function in c
Can you mix old-style and new-style function syntax?
What is define directive?
Is swift based on c?
Explain what is the difference between a string and an array?
How do you view the path?