COSC 111 Lecture Notes - Lecture 16: Array Data Structure, Boeing 737 Max, Method Stub

67 views6 pages
Verified Note

Document Summary

Declaring, creating, and initializing arrays int [] x; x = new int[3]; x[0] = 1; x[1] = 4; x[2] = 2; Declare: x is the name of the array with value null. Create: array x is made up of 3 integer elements. Initialize: refers to first element given value 1. Initialize: refers to second element given value 4. Initialize: refers to third elements given value 4. Declaring, creating, and initializing in one line int[] y = {1,4,2}; But, using this shorthand notation, must be all in one statement! (cid:449)ill gi(cid:448)e a(cid:374) error int[] y; y = {1,4,2}; You can do different things to each element in the array. Scanner in = new scanner(system. in); int [] ages = new int[20]; ages[0] = 12; 7 : single dimensional arrays ages[19] = 1; //output: 20 int [] myarray = new int[20]; For loops = used if elements are processed in the same fashion repeatedly.

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