AgeThing

import java.util.*; public class ArrList { public static void main(String[] args) { ArrayList<Integer> theAge = new ArrayList<Integer>(); Scanner scan = new Scanner(System.in); int co = 1; int yes = 1; while (yes == 1) { System.out.println("Put a negative to stop"); System.out.println("Put fam member age #" + co + " "); int ag = scan.nextInt(); theAge.add(ag); co = co + 1; if (ag < 0) { break; } } int tot = theAge.get(0); for (int i = 0; i < theAge.size(); i++) { tot += theAge.get(i); } double avg = (double)tot / (double)theAge.size(); System.out.println("The average is: " + 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.