An English statement is emitted in reverse order from the word unit. For example, "I am a boy", in reverse order after the discharge of "Boy a AM I"
All words are separated by a space with no other characters in the statement except the English letters
Interface description
/**
* Inverted sentence
*
* @param sentence The original sentence
* @return The inverted sentence
*/
public string Reverse (string sentence);
Enter a description:
An English statement is emitted in reverse order from the word unit.
Output Description:
Get a sentence in reverse order
Enter an example:
I am a Boy
Output Example:
Boy a AM I
Import Java.util.Scanner;
public class main{public
void Swap (char [] arr,int Front,int end) {while
(front<end) {
char tmp;
Tmp=arr[front];
Arr[front]=arr[end];
arr[end]=tmp;
front++;
end--
}
}
public string Swapwords (String str) {
char[] Chararry=str.tochararray ();
int len=chararry.length;
int begin=0;
Swap (Chararry, 0, len-1);
for (int i = 0;i < len;i++) {
if (chararry[i]== ') {
swap (Chararry, begin, i-1);
Begin=i+1
}
}
Swap (Chararry, begin, len-1);
return new String (Chararry);
}
public static void Main (string[] args) {
//TODO auto-generated method stub
StringBuilder string=new Stringbuil Der ();
Scanner Scanner =new Scanner (system.in);
while (Scanner.hasnext ()) {
string.append (Scanner.nextline ());
System.out.println (New Main (). Swapwords (new String));}}