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