CSE 142 Lecture 19: Arrays
CSE 142 verified notes
19/30View all
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.