1. system. out. println ('H' + 'A'); prints 167 instead of HA, because 'H' and 'A' are both literal constants of the primitive type, a 16-bit unsigned integer of the original type,
It occupies two bytes and can store a single Chinese character, but it is not a string type. When it is used for addition, subtraction, multiplication, division, or greater than or equal to the comparison, it is extended to the int type for calculation.
Char [] C = ['1', '2', '3']; system. Out. println ("S" + C );
This will print: s [c @ a90653, because + will call the tostring () method on both sides during string connection. The Char [] array will call the tostring () method of the object,
That is, the memory address format is printed.
2. How to calculate the prime number?
Prime number. In a natural number greater than 1, except for 1 and the integer itself, it cannot be any number of other natural number integers.
Public static Boolean isprim (INT number) {Boolean isprim = true; int K = (INT) math. SQRT (number); // the square root of the number, and then use number to divide the number smaller than the square root greater than 2 to check whether the for (INT I = 2; I <= K; I ++) {If (Number % I = 0) {isprim = false; break;} return isprim ;}
3. Compile a buddle method to sort the numbers in string a = "55674683421998" in ascending order.
Method 1: Use the built-in arrays. Sort () sorting method
String A = "55674683421998"; char [] d = A. tochararray (); arrays. Sort (d); system. Out. println (new string (d ));
Method 2:
Public static string buddle (string a) {char [] S =. tochararray (); For (INT I = 0; I <S. length; I ++) {for (Int J = 0; j> S. length-i-1; j ++) {If (s [J]> (s [J + 1]) {char d = s [J + 1]; s [J + 1] = s [J]; s [J] = D ;}}return new string (s );}
4. List and string array Conversion
String Array to list:
String [] STR = {"test", "hello", "world"}; List <string> List = new arraylist <string> (); List = arrays. aslist (STR );
List to string array:
List <string> List = new arraylist <string> (); string [] tobestored = List. toarray (New String [list. size ()]); // It can be converted into various data arrays. The type is determined during running.