Loading...
Loading...
Loading...
An online store keeps the prices of the items in a customer's cart in a list. Read the prices into an ArrayList<Integer> and print how many items there are, the total, the first price and the last price.
Items: <n>, Total: <sum>, First: <price>, Last: <price>.Example
Input
4 450 1200 90 799
Output
Items: 4 Total: 2539 First: 450 Last: 799
The first price is at index 0 and the last at index 3.
Try the problem first. Open one hint at a time.
Read n, then add n numbers with prices.add(sc.nextInt()).
The last item is at index prices.size() - 1.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor