Java Basics---What is an array (29)

Source: Internet
Author: User

What is an array

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!!

The 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 650) this.width=650; "src=" http:/ Img.mukewang.com/537074a400017cd905290196.jpg "style=" Border:0px;clear:both; "/>

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!


Code:

public class HelloWorld {

public static void Main (string[] args) {


Define an array to save five students ' scores

Int[] scores = {78, 93, 97, 84, 63};


The second score in the output array

System.out.println ("The 2nd result in the array is:" + scores[1]);

}

}



Operation Result:

The 2nd score in the array is: 93


This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547959

Java Basics---What is an array (29)

Related Article

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.