04_array - Arrays 1.4 Arrays This lecture Store and...

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

View Full Document Right Arrow Icon
1 1.4 Arrays " . . . By the way, we rank 10 th among the industrialized world in broadband technology and its availability. That’s not good enough for America. Tenth is 10 spots too low as far as I’m concerned. " - George W. Bush 2 Arrays This lecture. Store and manipulate huge quantities of data. Array. Indexed sequence of values of the same type. Examples. 52 playing cards in a deck. 14 thousand undergrads at UVa. 1 million characters in a book. 10 million audio samples in an MP3 file. 4 billion nucleotides in a DNA strand. 73 billion Google queries per year. 50 trillion cells in the human body. 6.02 × 10 23 particles in a mole. humper 0 sullivan 1 soffa 2 knuth 3 billg 4 rms 5 mst3k 6 alvin 7 index value 3 Many Variables of the Same Type Goal. 10 variables of the same type. // tedious and error-prone double a0 , a1 , a2 , a3 , a4 , a5 , a6 , a7 , a8 , a9 ; a0 = 0.0 ; a1 = 0.0 ; a2 = 0.0 ; a3 = 0.0 ; a4 = 0.0 ; a5 = 0.0 ; a6 = 0.0 ; a7 = 0.0 ; a9 = 0.0 ; a9 = 0.0 ; double x = a4 + a8 ; 4 Arrays in Java Java has special language support for arrays. To make an array: declare, create, and initialize it. To access element i of array named a , use a[i] . Array indices start at 0 . int N = 10 ; double [] a ; // declare the array a = new double [ N ]; // create the array for ( int i = 0 ; i < N ; i ++) // initialize the array a [ i ] = 0.0 ; // all to 0.0
Image of page 1

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

View Full Document Right Arrow Icon
2 5 Arrays in Java Java has special language support for arrays. To make an array: declare, create, and initialize it. To access element i of array named a , use a[i] . Array indices start at 0 . Compact alternative. Declare, create, and initialize in one statement. Default initialization: all numbers automatically set to zero. int N = 10 ; double [] a ; // declare the array a = new double [ N ]; // create the array for ( int i = 0 ; i < N ; i ++) // initialize the array a [ i ] = 0.0 ; // all to 0.0 int N = 10 ; double [] a = new double [ N ]; // declare, create, init 6 Vector Dot Product Dot product. Given two vectors x[] and y[] of length N , their dot product is the sum of the products of their corresponding components.
Image of page 2
Image of page 3
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