-1

So for the problem the user will enter as many double numbers as the want until they enter a negative number then it will stop the loop.

However I don't know how I would store all these numbers since I don't know how many the user will input and I can't use an array for this problem.

1 Answers1

1

You can use a List as such:

public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        List<Double> allValues = new ArrayList<>();
        double enteredValue;

        do{
            System.out.println("Enter a value");
            enteredValue = keyboard.nextDouble();
            allValues.add(enteredValue);
        } while (enteredValue >= 0);
    }