Programming: OJ systems Java programming language skills

OJ systems Java programming language skills

Frequently Asked Questions:
The most common kinds of questions still rely on arrays and strings, require skilled operation, and there is an array of strings for java provides a number of methods. Can simplify programming, but also for a programming language to master. The following list some of some of the techniques that he often encountered good use.

1, calculates the last word of the string array length: S [s.length - 1] .length ();
2, means changing case of characters:

  • Java string using the conversion method, uppercase: s.toUpperCase (); lowercase: s.toLowerCase ();
  • Using character ASCII code: uppercase to lowercase ( 'char' + 32); lowercase uppercase ( 'CHAR' - 32);

3, the data type conversion between:

  • String to char: s.charAt (index);
  • char is converted into String: String.valueOf (char);
  • String to int: Integer.parseInt (s); // return a value. Integer.valueOf (s); // returns the object. Integer.valueOf (s) .intValue (); // return a value.
  • int convert String: String.valueOf (i); // object. s = i + ""; // (splice) two objects.
  • is converted to char int: strong rotation (int) ( 'char'-48); // switch to an integer sub-string
  • int converted to char: strong rotation (char) (i + 48);

NOTE: Integer.parseInt (s, radix); A method according to binary conversion

4, the concept of substantially ASCII code: using 8-bit binary number indicates the 128 characters, remember common: (48 to 57) for the Arabic numerals 0 to 9; (65 ~ 90) 26 capital English letters; (122 ~ 97) No. 26 lowercase letters; uppercase and lowercase letters in mind that the phase difference of 32 ASCII code.

5, the correlation value calculation

  • Math.sqrt (n): square root; // find the cube root Math.cbrt (); squaring and Math.hypot ();
  • Math.pow (n, x): x-th power of n -;
  • Math.log (): natural logarithm, base-E;
  • Math.exp (x): index taking, e power of x;
  • Math.random (): Take a random number (0 to 1, the so often need to take a range domain);
  • Math.ceil (double a): rounding up;
  • Math.floor (double a): rounded down;
  • Math.round (double a): rounded to the nearest integer;

6, the median retention results

  • Simple Output: System.out.println (String.format ( "% 2f.", S));
  • Structure format object: DecimalFormat df = new DecimalFormat ( "# 00."); System.out.println (df.format (number));

7, some of the operations of the string

  • String split: str.substring (index); // str.split ( "");
  • String substitution: str.replace ();
  • String Matching: str.matches (regex);
  • String Reverse: new StringBuffer (str) .reverse ();

8, Map operation

  • Adding elements: map.put (key, value);
  • Get elements: map.get (key); value // key value corresponding to
  • Removing elements: map.remove (key); // remove the key corresponding to the key-value pairs
  • Comprising determining whether key: map.containsKey (key); // boolean function
  • Determining whether the air: map.isEmpty (); // true or false;
  • Map traversal: traversal key: for (Integer key: map.keySet ()) {}; traversal entity: for (Map.Entry <Integer, Integer> entry: map.entrySet ()) {};

(Continued) continuously updated

Guess you like

Origin www.cnblogs.com/small-world/p/11705913.html