Basic and miscellaneous

Basic and miscellaneous

1. exchange without the third variable

   int a = 8;
   int b = 11;

   a = a + b; // a = 19
   b = a - b  // b = 8
   a = a - b; // a = 11

Hypothesis: assume a a container

Howerver: maybe overflow ← plus may cause OverFlow

Bit Operation 位操作

‘^’ XOR Non-carrying addition

a = a^b 
b = a^b
a = a^b

2. Variable Type length Java

byte short int long
8 16 32 $- 2 ^ { 31 } \sim 2 ^ { 31 } - 1$ 64

$2 ^ { 16 } = 65536$

$$
\mathrm { T } = \operatorname { sigmoid } \left( \sum _ { i = 1 } ^ { 4 } f _ { i } \left( a _ { i } x + b _ { i } y + c _ { i } \right) \times w _ { i } \right)
$$

3. ArrayList

   int[] array = new int[] {...}
   >>> array.length

   # get Max elem
   int max = 0;
   for (.. i ..) {
     if (score[i] > max) max = score[i]
   }
   # 2-D MATRICS
   int[][] matrix = new int[][] {
       {1, 2, 3},
       {4, 5, 6},
       {7, 8, 9}
   }
   # TRAVERSE 2-D Array
   matrix.length
       matrix[i].length

   Reprint policy


《Basic and miscellaneous》 by David Qiao is licensed under a Creative Commons Attribution 4.0 International License
  TOC