08 -- Arrays.ppt - Arrays Java Arrays • An array is a...

This preview shows page 1 - 6 out of 6 pages.

Arrays Arrays Java
Image of page 1

Subscribe to view the full document.

Arrays Arrays An array is a collection object (consists of a collection of data) that holds a fixed number of values of the same data type.
Image of page 2
Arrays Arrays Each item in an array is an element and each element is accessed by its numerical index . The first element always has an index of 0. Examples of array declarations (with sample initialization) : // example 1 int[] myArray; myArray = new int[10]; myArray[0] = 100; // initialize 1st element myArray[1] = 200; // initialize 2nd element myArray[2] = 300; // etc. myArray[3] = 400; myArray[4] = 500; myArray[5] = 600; myArray[6] = 700; myArray[7] = 800; myArray[8] = 900; myArray[9] = 1000;
Image of page 3

Subscribe to view the full document.

Array Examples Array Examples // example 2 int[] myArray = new int[10]; for (int i = 0; i < myArray.length; i++) { myArray[i] = Keyboard.readInt();
Image of page 4
Image of page 5

Subscribe to view the full document.

Image of page 6
You've reached the end of this preview.
  • Fall '14
  • Array, new int

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern