JAVA uses the standard library to write a character string flip method by itself.

Source: Internet
Author: User

 

The algorithm is to extract each word by space, store it in a buffer for flip processing, and then add it to a new string. The new string completes the entire method process.

 

 

Public class ReserveString {public String reserve (String sentence) {String backS = new String (); StringBuffer temp = new StringBuffer (); int I = 0; while (I

 
  
= 0) {char ⅱ = temp. charAt (ii); char Sjj = temp. charAt (jj); temp. setCharAt (ii, Sjj); temp. setCharAt (jj, ⅱ); ii --; jj ++;} // obtain a single word and reverse the I ++; // skip the space backS = backS + temp +; // Add the flipped word and space temp = new StringBuffer (); // reset temp to store a single word} return backS;} public static void main (String [] args) {ReserveString reserveString = new ReserveString (); System. out. println (reserveString. reserve (I love programming rly ));}}

 


 

 

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.