Basic operations common to using Java practice algorithms

Source: Internet
Author: User

First, the use of Java practice algorithms often need to use the console's data input and output, the following record the basic use of the method:

Basic usage

1 ImportJava.util.*;2  Public classMain {3      Public Static voidMain (string[] args) {4Scanner cin =NewScanner (system.in);//Common scanner classes to get data5         intA = Cin.nextint ();//converts the input data to an int type assigned to a, the input data is separated by a space or tab, enter executes6System.out.println (a);//Console Output7}

Common:

1 ImportJava.util.*;2  Public classMain {3      Public Static voidMain (string[] args) {4Scanner cin =NewScanner (system.in);//Common scanner classes to get data5          while(Cin.hasnext ()) {//Loop Get6             inti = Cin.nextint ();//get int type data7             floatf = cin.nextfloat ();//get float type data8String s = cin.next ();//Get String9             Char[] chararrary = S.tochararray ();//converts a string into a character arrayTenString s2 = cin.nextline ();//get a row without being interrupted by a space or tab One System.out.println (S2);  A         } -     } -}
Second, the common string operation
    1. Length of string: Length ()
    2. SUBSTRING location: indexOf (), LastIndexOf ()
    3. String comparisons: "= =" and Equals () methods
    4. Uppercase and lowercase letters conversion: toLowerCase (); toUpperCase ()
    5. Character at the specified position: charAt ()
    6. SUBSTRING: subString ()
    7. Replace with: replace ()
    8. Merger: Concat ()
    9. Append: Append ()
    10. Insert: Insert ()
    11. Split: Split ()
    12. Convert to character array ToCharArray ()
    13. Convert any type to a string: string.valueof ()
    14. Judgment: StartsWith (), EndsWith ()

Basic operations common to using Java practice algorithms

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.