CS 18000 Lecture 5: Notes from Lecture 5: Arrays

46 views2 pages

Document Summary

Array: a list of values, arrays are homogenous, static, random access, and reference types. Analogy: a single variable that can hold multiple values. A method can take an array as parameter: in computesum(in[] a) A method can return an array as a return value: int[] sortintegers(int[] a) Arr. length will give how many rows there are (arr is the variable name) Arr[i]. length will give the number of elements in row i. For a 3 dimensional array, arr[2][4][3], arr[i][j]. length returns the number of elements in row i. In java, you do not need every row to have the same amount of elements which results in (cid:862)ragged right(cid:863) arrays. Int[] bloodpressure = new int [500]; int sum = 0; for (int value : bloodpressure) /*declares a variable named value that accesses each element in the matrix */ sum += value; This code will added all of the values together and then add to variable sum which is defined as 0.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents