Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- class CalculateTotal {
- public static void main(String[] args) {
- ArrayList<Double> expenses = new ArrayList<Double>();
- expenses.add(74.46);
- expenses.add(63.99);
- expenses.add(10.57);
- expenses.add(81.37);
- double total = 0;
- // Iterate over expenses for ArrayList
- for (int i=0; i<expenses.size(); i++){
- total = total + expenses.get(i); //get value of each item in the list and add it to the total
- }
- System.out.println(total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement