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

• Notes
• geekandroot
• 12

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

by Assist. Prof. M. Şükrü Kuran ART of COMPUTING Week 13: Arrays

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

Part 7: Arrays
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

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

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:
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};

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

ARRAYS We can get the LENGTH of an array by writing the array name followed by “.length” suffix
This is the end of the preview. Sign up to access the rest of the document.
• Spring '16
• Sukru
• Multiplication, Prime number, Primitive data type, Prof. M. Şükrü Kuran

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern