//main
public class 2d {
public static void main(String[] args) {
double[][] temperatures = {
{-5.5, -6.7, -3, -8.7, -13.3, -7.1, -6.5} ,
{-4.5, -19.7, -4, -8.7, -13.3, -21.9, -6.5},
{-5.5, -6.7, -3, -8.7, -13.3, -7.1, -6.5}
};
System.out.println(temps(temperatures));
}
//method
public static double temps(double[][] temperatures){
double highestTemp = 0.0;
for(int i=0; i<temperatures.length; i++){
for(int j=0; j<temperatures[i].length; j++){
if(temperatures[i][j] > highestTemp ){
highestTemp = temperatures[i][j];
}else if(highestTemp > temperatures[i][j]){
highestTemp = temperatures[i][j];
}
}
}
return highestTemp;
}
}
The correct output is suppose to return -3 since the largest number in the 2d array is -3, but my code returns -6.5 anyone know how to fix this?