Hey, im trying to make a program where you can type in alot of values, and then it should return the sum of them, how many values ive typed in and the highest/lowest value. My code currently looks like this
import java.util.Scanner; public class OppgaveC { static double maksTemp = Integer.MAX_VALUE; static double minTemp = Integer.MIN_VALUE; static double sum = 0; static int antallTemp = 0; public static void main(String[] args) { temperaturer(args); } public static void temperaturer(String[] args) { System.out.println("Skriv temperaturer"); Scanner in = new Scanner(System.in); System.out.println(fåSvar(in)); System.out.println(maksTemp); } public static double fåSvar(Scanner in){ boolean kjør = true; while (kjør == true) { double fåTemperaturer = in.nextDouble(); if (fåTemperaturer == -100) kjør = false; else { if (fåTemperaturer > maksTemp) maksTemp = fåTemperaturer; if (fåTemperaturer <= minTemp) minTemp = fåTemperaturer; sum+= fåTemperaturer; antallTemp++; } } return sum; } }
Problems im having, it wont return the correct min or max value, and im yet to figure out how to make it return all the different values at the same time Any thoughts?