ARRlist

import java.util.*; public class Arrlist { public static void main(String[] args) { ArrayList<Integer> ageinfo = new ArrayList<Integer>(); Scanner userInput = new Scanner(System.in); int year; int average = 0; boolean Kovi = true; while(Kovi){ System.out.println("Enter your age, your siblings age, then your parents age. (negative number to calculate average)"); year = userInput.nextInt(); if(year>=0) ageinfo.add(year); else Kovi = false; } int all = ageinfo.size(); for(int i = 0; i < all; i++){ average += ageinfo.get(i); } average=average/(all); System.out.println("Average age in your family is " + 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.