rec6 - Arrays S177 Week 06) Announcements Project 2 due...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Arrays S177 Week 06) Announcements Project 2 due today Project 3 will be posted tomorrow Questions? Definitions Homogeneous If you have an array A, then A[0] = 0 and A[1] = string is not valid Static Size has to be specified when creating the array Creating an array int age; Creates a variable 'age' which can be used to reference an array of int type. No data can be stored in it age = new int[10]; Now this variable can be used to store data. This array can have 10 int values. These two instructions are equivalent to int age = new int[10]; Accessing data in an array To store a value in an array at some position, do : age[position] = value; So, if you want the first value in the array 'age' as '1', then do : age[0] = 1; Note args was an array of String type. Same as args, if you want to access a value in 'age', you write age[position] Remember that in java most of the time numbering starts with 0. i.e. the first value in 'age' is age[0] and not age[1] cont... This is one way of initializing and assigning values to an array: String days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; In this example, days is an array of size 7. Length of array To get the length of String str, we used...
View Full Document

Page1 / 25

rec6 - Arrays S177 Week 06) Announcements Project 2 due...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online