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 we use conio h in c?
How to throw some light on the b tree?
How can I rethow can I return a sequence of random numbers which dont repeat at all?
A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none
Can you define which header file to include at compile time?
Difference between Function to pointer and pointer to function
write a sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?
What is the use of parallelize in spark?
Does c have an equivalent to pascals with statement?
What is a static function in c?
What is the heap in c?
I have seen function declarations that look like this
Explain about the functions strcat() and strcmp()?
What is the purpose of clrscr () printf () and getch ()?
Explain how do you search data in a data file using random access method?