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
What is the purpose of ftell?
What is a memory leak? How to avoid it?
How can I sort more data than will fit in memory?
What is call by value in c?
What is the use of static variable in c?
please send me the code for multiplying sparse matrix using c
c program for searching a student details among 10 student details
Can 'this' pointer by used in the constructor?
What is bin sh c?
which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above
How can I remove the leading spaces from a string?
What is an example of structure?
What is pointer in c?
What is identifiers in c with examples?
What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.