double temperature1;
double temperature2;
double temperature3;
double[] temperature = new double[3];
<element type>[] <name> = new <element type>[<length>];
Type | Value |
---|---|
int | 0 |
double | 0.0 |
char | '\0' |
boolean | false |
objects | null |
<element type>[] <name> = {<value>, <value>, ..., <value>};
Example:
int[] daysIn = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int myGrade = grades[2];
for (<type> <name> : <array>) {
<statement>
<statement>
<statement>
...
}
Example:
for (int x: temps) {
if (x > average) {
above++;
}
}
for (int idx=0; idx<temps.length; idx++) {
if (temp[idx] > average) {
above++;
}
}
NOTE: .length is a property of an array, not a method (no parameters).
System.out.println(list); // Bad, prints garbage
System.out.println(Arrays.toString(list)); // Better
// [17, -3, 42, 8, 12, 2, 103]