1 / 10

Web Programming

http://discern.uits.iu.edu:8790/S517/S517.html. Web Programming. Array Xiaozhong Liu. An Array of… (Strings, integers, doubles). A list of Object. Information problem…. Output. Input. Process. An Object. A Variable (String, int , Double). Temperature File, 5 temperatures.

amato
Télécharger la présentation

Web Programming

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. http://discern.uits.iu.edu:8790/S517/S517.html Web Programming Array Xiaozhong Liu

  2. An Array of… (Strings, integers, doubles) A list of Object Information problem… Output Input Process An Object A Variable (String, int, Double)

  3. Temperature File, 5 temperatures double [ ] temperatures = new double[5]; //Write to those variables (Array) 30.5 -15.3 0 60.35 18.12 temperatures [0] temperatures [1] temperatures [2] temperatures [3] temperatures [4]

  4. Type Array name String Array String [ ] students = new String [25]; Array Declarations Variable value int Array int [ ] age = new int [100]; double double [ ] heights = new double [50];

  5. int [ ] numbers = new int [50]; … //e.g.read from a file ‘Average numbers??? Average of numbers int sum = 0; double average; for (int index = 0; index<50; index++) { sum = sum + numbers [index]; } average = ????????

  6. int [ ][ ] numbers = new int [2][3]; 2 – Dimensional Array

  7. int [ ][ ] numbers = new int [3][5]; double average, sum = 0; 2 – Dimensional Array • for (int row= 0; row<3; row++) { • for (intcol = 0; col < 5; col++) { • sum = sum + numbers [row] [col]; • } • } • average = ?????????

  8. int[ ] numbers = new int[20], squares = new int[20]; for (inti = 0; i < numbers.length; i++) { numbers[i] = i + 1; } //Compute squares??? //Average of squares??? Practice

  9. double [ ] numbers = new double[5]; double [ ] numbers = {2.1, 43.1, 0, -0.3, 35.0}; You can use for loop How about dynamic array? Fix length array

  10. double [ ] numbers = new double[5]; import java.util.ArrayList; ArrayListal = new ArrayList(); al.add("C"); al.add("A"); al.add("E"); al.add(1, "A2"); for (int i = 0; i < al.size(); i ++) { Stringitem = (String)al.get(i); System.out.println(item); } Dynamic array

More Related