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 (int i = 0; i < expenses.size(); i++) { total += expenses.get(i); } System.out.println(total); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter