Web-android Engineer first-6-1 what is an array

Source: Internet
Author: User

Source: http://www.imooc.com/code/1514

Q: Write code to save 4 students ' test scores.

A: Simple ah, define 4 variables Bai

Q: That "calculates the exam results of 400 students all year round", swollen

For:.......

array , you can help you to solve the problem properly!!

An array can be understood as a huge "box" in which multiple types of data can be stored sequentially, such as an array of type int scores store 4 students ' scores

The elements in the array can be accessed by subscript, and the subscript starts at 0. For example, you can get the first element in the array by scores[0], scores[2] can take the third element 92!

Task

Happy practice time again!!

An array scores is defined in the editor to hold the test scores for five students, please complete the code in line 8 , and the second result in the output array

The result of the operation is:

1  Public classHelloWorld {2      Public Static voidMain (string[] args) {3 4         //define an array to save five students ' scores5         int[] scores = {78, 93, 97, 84, 63 };6 7         //the second score in the output array8System.out.println ("The 2nd result in the array is:" +            );9     }Ten}

1  Public classHelloWorld {2      Public Static voidMain (string[] args) {3 4         //define an array to save five students ' scores5         int[] scores = {78, 93, 97, 84, 63 };6 7         //the second score in the output array8System.out.println ("The 2nd result in the array is:" + scores[1]);9     }Ten}

Lao Chit chat When:

Learning Java today, I found a lot of the same syntax as the C language, for example, do andswitchcaseDefault break, such as the definition of the array is a little different, C is to put the brackets in the variable name, but Java is to put the brackets before the variable name, using the array element is placed in the square brackets after the variable name, and the subscript is 0 start

Web-android Engineer first-6-1 what is an array

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.