So I have a set of data for Max weather averages, and I have constructed a while loop:
I want it to ignore the first line, that is why I do: scn.nextLine();
.
Take note that all of this is within the main method
.
//MAX MAX
float maxMax = 0;
try {
File file = new File("weather.txt");
Scanner scn = new Scanner(file);
scn.nextLine();
String line;
while (scn.hasNextLine()) {
line = scn.nextLine();
//MAX MAX
String maxTempString = line.substring(102, 108);
maxTempString.trim();
float maxTemperature = Float.parseFloat(maxTempString);
if (maxTemperature > maxTemperature) {
maxMax = maxTemperature;
System.out.println(maxTemperature);
}
} catch (FileNotFoundException e) {
System.out.println("File: " + e + " not found");
}
System.out.println(maxMax);
When I loop through this data, It outputs various data like:
50.0 50.0 42.8 48.2 46.4 46.4 55.4 71.6 71.6 69.8 51.8 57.2
Now I'm having a hard time with what I should do within the if statement, my current statement returns 0
I just need some pointers, I am looking to find the Maximum number of the Max weather list. Thanks in advance.
Maybe
if (maxTemperature > maxMax)
I don't know where minTemperature comes from.
将if (maxTemperature > maxTemperature)
更改为if (maxTemperature > maxMax)
应该可以解决问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.