Changes between Version 1 and Version 2 of ControlSystems/SoftwareTeam/Training/GettingStarted/Arrays


Ignore:
Timestamp:
Aug 3, 2020, 5:31:23 PM (5 years ago)
Author:
Angelina Zhou
Comment:

changed code that was under "The following declares a variable that stores 50 integers:"

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/Arrays

    v1 v2  
    11Programs 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
    23{{{
    34  int meeting1_attendees;
     
    67  int meeting4_attendees;
    78}}}
    8 But that's awkward (especially if you met 50 times during the season).  Fortunately, Java offers a type of variable called an ''array''. 
     9But that's awkward (especially if you met 50 times during the season).  Fortunately, Java offers a type of variable called an ''array''.
    910
    1011The following declares a variable that stores 50 integers:
     12
    1113{{{
    12    int meeting_attendees[50];
     14   int meeting_attendees[]=new int[50];
    1315}}}
    1416To print the attendees at meeting 3 you would use:
     17
    1518{{{
    1619   System.out.println("Meeting 3 attendees:"+meeting_attendees[2]);
     
    1922
    2023Arrays are particularly powerful when you combine them with loops; consider the following:
     24
    2125{{{
    2226   for (int mtg=0; mtg<50; mtg++) {
     
    2630Loops and arrays give you a concise way to programmatically process large collections of data.
    2731
    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]