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
- Length of string: Length ()
- SUBSTRING location: indexOf (), LastIndexOf ()
- String comparisons: "= =" and Equals () methods
- Uppercase and lowercase letters conversion: toLowerCase (); toUpperCase ()
- Character at the specified position: charAt ()
- SUBSTRING: subString ()
- Replace with: replace ()
- Merger: Concat ()
- Append: Append ()
- Insert: Insert ()
- Split: Split ()
- Convert to character array ToCharArray ()
- Convert any type to a string: string.valueof ()
- Judgment: StartsWith (), EndsWith ()
Basic operations common to using Java practice algorithms