ArrayList

import java.util.*; public class ArrList { public static void main(String[] args) { ArrayList<Integer> Ages = new ArrayList<Integer>(); Scanner scan = new Scanner(System.in); int co = 1; int bat = 1; while (bat == 1) { System.out.println("Put fam member age #" + co + " "); int ag = scan.nextInt(); Ages.add(ag); co = co + 1; if (ag < 0) { break; } } int tot = Ages.get(0); for (int i = 0; i < Ages.size(); i++) { tot += Ages.get(i); } double avg = (double)tot / (double)Ages.size(); System.out.println("Avg: " + avg); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.