1 / 2

Array: How do you group multiple values (of the same type) together

Array: How do you group multiple values (of the same type) together. // Array optimizations int []ar = new int [] {2, 4, 6}; // equivalent to int []ar = new int[3]; ar[0] = 2; ar[1] = 4; ar[2] = 6; // common mistakes. THIS DOES NOT // MAKE A COPY. ar and br point to

cher
Download Presentation

Array: How do you group multiple values (of the same type) together

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Array: How do you group multiple values (of the same type) together // Array optimizations int []ar = new int [] {2, 4, 6}; // equivalent to int []ar = new int[3];ar[0] = 2; ar[1] = 4; ar[2] = 6; // common mistakes. THIS DOES NOT // MAKE A COPY. ar and br point to // the exact same array structure int []br = ar; // the array which is jointly// pointed to by ar and br has now // changed. br[3] = 19; int [ ] ar; define a variable that refers to an array of int values After the statement above, what is the value of ar? ar null instantiate contiguous array of six possible int values ar = newint [6]; ar 0 1 2 3 4 5 ar [0] is the leftmost value ar [5] is the rightmost value An array can be traversed easily using a while statement. // INPUT Scanner sc = new Scanner (System.in); int []p = new int[3]; System.out.println ("Enter x, y, z values for point"); int i = 0; while (i < p.length) { p[i] = sc.nextInt(); i++; // ADVANCE } // array is now populated with p[0] .. p[2] CS2102 Handout: arrays

  2. a b h = 1 Write program to read in a set of10 numbers, whose int values represent f(x) over the range 0..9Use the trapezoid rule to compute Where a=0 and b=9. For example,the area below is 56.5   Write From Scratch!!!!! CS2102 Handout: arrays

More Related