Java Notes Chapter Eighth

Source: Internet
Author: User

1 definition of the array:

is a set of related variables.

2 Elements of an array:

Identifier:

First, as with variables, in computers, arrays also have a name, called an identifier, that distinguishes different arrays.

Array elements: When you give the array name, which is the array identifier, you want to store the data in the array, which is called the array element.
Array subscript: In the array, in order to correctly get the elements of the array, they need to be numbered, so that the computer can be accessed according to the number, this number is called the array subscript.
Element type: The array elements stored in the array should be of the same data type, such as the student's scores can be stored in the array, and each student's scores can be stored with integer variables, so that its element type is integer type. 3 Structure of the array:
      1   Array There is only one name, the identifier, such as scores.  2   array elements in the array ordinal number, the number is subscript, it indicates the position of the element in the array, the first element is numbered 0, so the subscript of the array is 0. 1.2.3.4 and so on.          3   Each element in the array can be accessed by subscript.       Because elements are stored sequentially, each element is fixed to a straight subscript, so you can quickly access each element by subscript.  4    array size (length) is the maximum number of elements that an array can hold. Defining an array also defines its size. If the array is full but continues to store data in the array, the work program will go wrong,                  This is called array out of bounds.  4   Using arrays: Declaring an array →→ allocating space →→ Assigning a value →→ processing the data declaring an array: (two formats for declaring an array)     1 data type []   array name;  &NB Sp                2   data type     array name [], such as:       &NBS       P  1   int []  scores;      2   double  height[];     &NBSP;3 &NB Sp String[]  names; Allocate space: array name = new data type [array length] such as: 1  scores = new Int[30]       &N Bsp type int of length 30 2  height = new double[30]    //length is 30 DOUBLCType    3  names = new String[30]   assignment of String type with length 30: array name [subscript value] = assigned value;             : scores[0] = 64;                &NBSP;SC ORES[1] = 38;                 scores[2] = 94;        &NBS P            &nbsp, .....      Note * * The subscript value must start from zero * * For example   declares a 5-length array subscript [0] [1] [2] [3] [4]. For loop assignment: For example: Scanner  input  = new Scanner (string.in);//scanner for (int i=0;i<30;i++) {&N        bsp;  Scores[i] = Input.nextint ();//Receive keyboard input values from the console for cyclic assignment. The syntax data type [] Array name ={value 1, value 2, value 3,...... declared array   allocated space and assignment triad Value n}; data type [] Array name = new array type [this square bracket is null]{value 1, value 2, value 3,...... Value n};   such as: 1   int[] scores = {64,38,94, ...} ; 2   int[] scores = new int[] {64,38,94, ...} The data is processed: there is no specific syntax, that is what to do.   

Java Notes Chapter Eighth

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.