1 / 15

Day 23

Day 23. 6.1 Arrays. Array Basics. An Array is a data type structure that can hold multiple values An array is like a ladder. You can specify how long the ladder should be and what values each step of the ladder has. Array Basics.

oberon
Download Presentation

Day 23

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Day 23 6.1 Arrays

  2. Array Basics • An Array is a data type structure that can hold multiple values • An array is like a ladder. You can specify how long the ladder should be and what values each step of the ladder has

  3. Array Basics • An Array is a data type structure that can hold multiple values

  4. Defining Arrays Data_Type[] arrayName = new Data_Type[# of steps];

  5. Defining Arrays Data_Type[] arrayName = new Data_Type[# of steps]; For example, double[] temperatures = new double[10]

  6. Defining Arrays Exercise:define an array which has - the name sentence- length/#steps of 5

  7. Setting Values in Arrays ArrayName[0] = first value;ArrayName[1] = second value;…ArrayName[n - 1] = nth value;

  8. Setting Values in Arrays Exercise: set the values of the array sentence

  9. Setting Values in Arrays *Note that not every step in the array needs to be defined.

  10. Reading values in Arrays The first value in the array is the 0thposition, the second value in the array is 1st position, …. the nthvalue in the array is thn-1 thposition.

  11. Accessing values in Arrays To access the value at its third step, ArrayName[2];

  12. Accessing values in Arrays Exercise: Print out the last word in your array

  13. Accessing values in Arrays Exercise: Print out the last word in your array

  14. Exercise: print out every value of sentence with a for loop

  15. Exercise: Add a clause to your for loop. If one of the words of your array is “yo”, then it should alert the user of “highly unprofessional language used”.Otherwise, print “all words are professional”.

More Related