Java, Part 6 - ART of COMPUTING Week 13 Arrays by Assist...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
by Assist. Prof. M. Şükrü Kuran ART of COMPUTING Week 13: Arrays
Image of page 1

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

View Full Document Right Arrow Icon
Part 7: Arrays
Image of page 2
ARRAYS Keeping a Group of Variables x[0] x[1] x[2] x[3] x[4] x[5] x[6] x[7] x[8] x[9] x[10] x[11] 6 8 45 233 -4 0 4 67 31 3456 34 -69 An “ int array of size 12: The index number 1 st element NOTE : The first element of each array is ALWAYS called the 0 th element. NOTE : The indices can only be >= 0
Image of page 3

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

View Full Document Right Arrow Icon
ARRAYS Arrays are objects (non-primitive types) that occupy space in memory. Declaration of Arrays NOTE : The LAST element in an array of size “n” is the element with index “n - 1“ int[] x = new int[12]; Declaring an Integer Array of size 12:
Image of page 4
ARRAYS After declaring the array, we can use each element of an array like a variable: Use of Arrays Example: Write a program that reads an integer N, then reads that many integers and calculate the average of these numbers. x[3] = 2; x[4] = x[3] * 5; x[5]++; We can also initialize arrays like other primitive data types. int[] n = {10, 40, 3, -2, 99};
Image of page 5

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

View Full Document Right Arrow Icon
ARRAYS We can get the LENGTH of an array by writing the array name followed by “.length” suffix
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ 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