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

61 views4 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! will give an 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; ages[19] = 1; More examples: int [] myarray = new int[20]; For loops = used if elements are processed in the same fashion repeatedly int[] nums = new int[100];

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