String-07. Irony-Enhanced Edition (20)

Source: Internet
Author: User

Given an English sentence, you are asked to write a program that reverses the order of all the words in the sentence.

input Format: The test input contains a test case that gives a string with a total length of not more than 500 000 in a row. A string consists of several words and a number of spaces, where the word is a string of letters (case-sensitive), separated by several spaces between the words.

output format: the output of each test case occupies one line, output the sentence after the reverse, and guarantee only 1 spaces between words.

Input Sample:
Hello World here   I Come
Sample output:
Come I here World Hello
Import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner cin = new Scanner (system.in); S Tring str = cin.nextline (); string[] STRs = Str.split (""); Boolean isFirst = true;for (int i = strs.length-1; I >= 0; i--) {Strs[i] = Strs[i].trim (), if (IsFirst &&!strs[i].equals ("")) {System.out.print (strs[i]); isFirst = false;} else if (!strs[i].equals (")") {System.out.print ("" + Strs[i]);}}}

String-07. Irony-Enhanced Edition (20)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.