NewArrayMeme

//team: sejin & skooklar import java.util.*; public class AgeArrayList{ public static void AgeArrayList(){ Scanner sc = new Scanner(System.in); boolean plugging = true; ArrayList<Integer> age = new ArrayList<Integer>(); int year; int average = 0; while(plugging){ System.out.println("Enter the ages of your family member (negative number to end): "); year = sc.nextInt(); if(year>=0) age.add(year); else plugging = false; } int length = age.size(); for(int i=0; i<length; i++){ average += age.get(i); } average=average/(length); System.out.println("Average: " + average); } }

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.