December 13th, 2013, 04:37 AM
[RESOLVED] Scanner Class with the ArrayList
Hello Java friends,
I am new to joining a site like this so let me get straight to the point. I am trying to make an ArrayList that stores the users input of the ages of their grandchildren. I have this code started but am lost from there as I can not find enough information on the web on how to accomplish this task.
Yes, I am an IT student with Java being my last class till I graduate, but this is not an actual assignment. I need to try to learn this task as i will be using a similar function in my project. The age of the grandchildren is something i made up as I seem to be missing how to store user inputs (specifically <Integers>), then to sum all the inputed ages (for right now I am just trying to show all the inputed ages as an array). I will be grateful for any and all help I receive.
public class GrandChildren
public static void main(String args)
Scanner in = new Scanner(System.in);
//My ArrayList (i am getting an redundant data type here)
ArrayList<Integer> childAge = new ArrayList<Integer>();
//Asks for the ages of the grand children
System.out.println("What are the ages of your grand children? ");
int age = in.nextInt();
if (age > 0)
for(int i = 0; i <= childAge.size(); i++)
//I am getting an error here
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!