Chapter 9

4 Pages
Unlock Document

Ryerson University
Information Technology Management
ITM 200
Vikraman Baskaran

Arrays Arrays is a data structure that represents a collection of the same types of data Initializing an Array int [] num = {0,1,2,3,4,5}; or - int [] num = new int [6]; num [0] = 0; num [1] = 1; num [2] = 2; num [3] = 3; num [4] = 4; num [5] = 5; Often, in a program, you need to duplicate an array or a part of an array. In such cases you could attempt to use the assignment statement (=), as follows: list2 [i]= list1[i]; // Whatever is in list[], is being copied into the array list2 [] Passing Arrays to Methods In the printArray() Method public static void printArray(int[] array) { Main Method for (int i = 0; i < array.length; i++) { int[] list = {3, 1, 2, 6, 4, 2}; System.out.println(array[i] + " "); printArray(list); } printArray(new int[]{3, 1, 2, 6, 4, 2}); } Array Search (Linear) Within the array it is looking for a specific value (double, char, int, String ………) It starts for the start for the box, the second and so on And then it finds the value it is looking, after looking in each box before If i = 0, the value 3 is at 5, in the array Array Search (Binary) Must be in ascending or descending order Within the array it is looking for a specific value (double, int ) If there are 8 boxes in the array, you cross from end to end After you will have to 2 numbers left Take the number to the left, in the next line, start with the number on the right, if the number on th
More Less

Related notes for ITM 200

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.