Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/Arrays
- Timestamp:
- Aug 3, 2020, 5:31:23 PM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/Arrays
v1 v2 1 1 Programs frequently need to deal with many instances of something: for example consider a program that how many people attended each robotics meeting. You could create a variable for each robotics meeting: 2 2 3 {{{ 3 4 int meeting1_attendees; … … 6 7 int meeting4_attendees; 7 8 }}} 8 But that's awkward (especially if you met 50 times during the season). Fortunately, Java offers a type of variable called an ''array''. 9 But that's awkward (especially if you met 50 times during the season). Fortunately, Java offers a type of variable called an ''array''. 9 10 10 11 The following declares a variable that stores 50 integers: 12 11 13 {{{ 12 int meeting_attendees[ 50];14 int meeting_attendees[]=new int[50]; 13 15 }}} 14 16 To print the attendees at meeting 3 you would use: 17 15 18 {{{ 16 19 System.out.println("Meeting 3 attendees:"+meeting_attendees[2]); … … 19 22 20 23 Arrays are particularly powerful when you combine them with loops; consider the following: 24 21 25 {{{ 22 26 for (int mtg=0; mtg<50; mtg++) { … … 26 30 Loops and arrays give you a concise way to programmatically process large collections of data. 27 31 28 === Extra credit 29 * Read more about [https://www.geeksforgeeks.org/arrays-in-java/ Java arrays] 32 === Extra credit === 33 * Read more about [https://www.geeksforgeeks.org/arrays-in-java/ Java arrays]