COP 2510 Study Guide - Quiz Guide: Array Data Structure, Foreach Loop, Pariah Dog

116 views6 pages

Document Summary

An array of size n is indexed from zero to n-1. This array holds 10 values that are indexed from 0 to 9. In java, arrays are objects that must be instantiated. The name of the array (scores) is an abject reference variable. The scores array could be declared as: int [] scores = new int[10]; The type of variable scores is set to a new array object that can hold 10 integers. Java provides two ways to declare arrays: int [] grades; int grades []; The first is consistent with other types of declarations. Declared type is explicit if array brackets are associated with element type. Other example of array declarations int [] weights = new int [2000]; Double [] prices = new double [500]; Boolean [] flags; flags = new boolean [20]; To reference a particular value or element, use the array name followed by the position or index in brackets.

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

Related Documents