JAVA ----week4

  week4(  ch7 ch8)
Insert a debug of shortcuts:
F5 depth step by step (to enter each method)
F6 step by step (do not enter method)
F7 If the current entering a method can skip to the end
F8 run a breakpoint
  java array
  
 Creating array declaration:
       1. Declare double [] a; (normal) / double a [];
  (Unallocated space), but the basic data types will allocate memory in the statement, just a reference to the storage location of the array, the default is null (the space of only a pointer right), it is actually not create an array of
       2. Create a = new double [10];
  Actually doing two steps: Create an array to the new array reference assigned to a
  3. Create the assignment statement with double [] a = new double [10];
       Display array length directly a.length
  Double [] = new new Double A [10];
  for (int I = 0; I <a.length; I ++) {
   A [I] = Math.random () * 10;
  }
  the System .out.println ((int) a [. 5]);
 }
      4. initialization double [] a = {1,2,3} ; ( declaration creates initialization)
      The one-dimensional array: the length (fixed length, variable length) ,
  Generally can not variable length, has not learned to use other methods
The Vector new new V = the Vector (0,1);
for (int I = 0; I <10; I ++)
    v.addElement (. (New new Integer (I)) toString ());

v.addElement ( "10");
System.out.printLn ((String) v.elementAt (5 ));
 two-dimensional array:
          int = A new new int [] [] {{2.2.2} {1,2} {3,2,1, 2}}
          may not be rectangular (row is not equal to the column), a, a [0] , a [1], a [2] each have an id
          how to traverse! ! !
          N-dimensional multidimensional array
 through the array:
         1. for iterating
          2.foreach form: length of the array may not need to output the array element order
          for (Double D: mylist)
          {systemout.println (D);} represents in each array mylist d in the following elements, but not the operating elements
          {IF (d> Result) Result = d;  
          Debug amount can be changed directly
       
      Processing data
          input value - initialize
          the random number - Initialize
           Display - Array
   Array elements are summed
          to find the largest element
          to find the largest element index
          random elements to disrupt ordering
          mobile element
 
 Array copy ---- memory problems:
  1. b = a 
         the actual content b is the original point of space has become a garbage waste is recycled java virtual machine, b this pointer points to a space, in fact, is not the copying of content (common data type is) even if the difference between the two will become the same length, also become a another variant, observation point to the same address as id
  2.循环中复制
     int[] a={1,2,3};
     int[] b=new int[10];
  for(int i=0;i<a.length;i++)
           b[i]=a[i];
  for (int i : b) {
   System.out.println(i);
  }
! ! ! The length of the array of different lengths, for the attention
 When b is larger than a length of no error (a code) a runtime error
     int[] a={1,2,34,5,6,7,8,21,2,3,4,5};
     int[] b=new int[10];
  for(int i=0;i<b.length;i++)
           b[i]=a[i];
  for (int i : b) {
   System.out.println(i);
  }
This would not be wrong
          3.arraycopy
          System.arraycopy (a, a, b, 2,4) 4 to start copying the subscript b 2 starts from a subscript 1
          with an i value for1, 2 by i said length i 4 of
         4. clone
          b = a.clone, b but a constant change, a simple method that: id different
    
      methods to pass an array
          pass array parameters: id actually pass
          if the number of parameters mismatch error
          is available in the int function defining Params ... a represents any number or array, can be seen a.length
          returned from the array method of
          a variable length argument list
      arrays class
Class conversion functions:
  1. String - "array of characters
  String a="eufb";
  char[] b=a.toCharArray();
  System.out.println(b[2]);     f
  char c=a.charAt(1);
  System.out.println(c);     u
  System.out.println(a.length());    4
  System.out.println(b.length);    4
 
  2. char array - "String
  String hard=String.valueOf(b);
  System.out.println(hard);    eufb
To accept a single character:
    java The scanner does not have this method can only be accepted as a string
INPUT = new new Scanner Scanner (the System.in);
  String input.next S = (); // Scanner class does not provide a direct method for receiving a character, here as a string receiving;
  System.out.println (s.charAt (0)); // call charAt string () method it wants to get the first character

*/

Guess you like

Origin www.cnblogs.com/jingjing1234/p/11543744.html