import java.util.Scanner;
public class Messdaten {
public static double temperaturInDurchschnitt(Scanner sc){
int year= 0, month= 0 , day= 0;
String discription = "";
double value= 0.0;
double warmest= -273.15;
int i = 0;
double sum = 0.0;
while (sc.hasNext()) {
year= sc.nextInt();
month= sc.nextInt();
day= sc.nextInt();
discription = sc.nextLine();
if (discription.equals("Temperatur")){
value= sc.nextDouble();
sum = sum + value;
if (value>= warmest){
warmest = value;
}
}
value = sc.nextDouble();
} sc.close();
System.out.println("highest Temperatur " + "(" + warmest+ ")" + "at" + day+ month+ year);
return sum/i;
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
temperaturInDurchschnitt(sc);
}
}
i am trying to gather the values of temperatur only from a given text:
2018 10 16 Luftdruck 1014.7
2018 10 17 Niederschlag 1.3
2018 10 15 Temperatur 18.2
2018 10 16 Niederschlag 0.0
and return the highest temp at which day .
2018 10 17 Temperatur 16.8
Remarks:
//1
you need to know when to stop reading the input - you can check if the next line is blank for example//2
to avoid the problem mentioned in the comment, I would read the whole line and parse each of the space separated parts to the expected types//3
seems that you want to store theyear
,month
andday
of the warmest day, so it should be updated only when you find the higher temperature.