i am currently working on a java code that takes input from user and outputs the size of arraylist, the sum of numbers entered, the average and the maximum number entered. i have not been able to complete the sum as the for loop is not calculating result. I would appreciate any suggestions. my code is as follows.
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
double size = 0;
double a = -999;
double total = 0;
Scanner in = new Scanner(System.in); // scanner object for user input
ArrayList<Double> inputs = new ArrayList<Double>();
System.out.println("Enter a number, to terminate enter -999 :");
while (in.hasNextDouble()) {
//assign the nextDouble to a variable
double tmp = in.nextDouble();
//test the variable
if (tmp != a) {
//add the variable
//if you want to add -999 to the inputs then this next line above the test.
inputs.add(tmp);
System.out.println("Enter a number, to terminate enter -999 :");
} else {
inputs.size(); // get size of input
System.out.println("Numbers entered: " + inputs.size());
break;
}
}
for (double sum : inputs) {
total += sum;
System.out.println("The sum of numbers entered is " + total);
break;
}
}
}