Can someone explain these lines of code? This program is for generating temperature of ten locations. I’m learning Array and having difficulty to understand some things.
public class WeatherFan
{
public static void main(String[] args)
{
//Temperature Array
float[][] temperature = new float[10][365];
//Generate Temperatures
for (int i = 0; i < temperature.length; i++)
for (int j = 0; j < temperature[i].length; j++)
temperature[i][j] = (float)(45.0*Math.random() - 10.0);
// Calculate the average per location
for (int i = 0; i < temperature.length; i++)
{
// place to store the average
float average = 0.0f;
for (int j = 0; j < temperature.length; j++)
average += temperature[i][j];
// Output the average temperature of the current location
System.out.println("Average temperature at location +"
+ (i+1) + " = " + average/(float)temperature[i].length);
}
}
}
Explain temperature[i].length and temperature[i][j] in these lines. I’m having difficulty to understand [i] and [i][j] what will these lines do and how will? Please explain these.
for (int j = 0; j < temperature[i].length; j++)
temperature[i][j] = (float)(45.0*Math.random() - 10.0);
2007-06-30
02:47:00
·
2 answers
·
asked by
Adnan A
1
in
Computers & Internet
➔ Programming & Design