CSE 142 Lecture 19: Arrays

54 views4 pages
Verified Note

Document Summary

1 // this short program calculates the average temperature for a sequence. 2 // of days and reports how many days were above average. 4 // note the use of an array to store the temperatures, even though we. 5 // don"t know how many days there will be before the program runs. 6 // we would not have been able to write this program without arrays. 10 public static void main(string[] args) { 18 for ( int i = 0; i < temps. length; i++) { 27 for ( int i = 0; i < temps. length; i++) { 34 system. out. println( "there were " + numaboveavg + " days above average. Arr[5] java. lang. arrayindexoutofboundsexception: array index (5) is greater than or equal to array. // notice that the length does not have parentheses and it works! // yes, this is just one of those java notes to know, when taking length of arrays, no parentheses.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions