Question: I would like to store 2 elements in 1 index of an array. For example : private static Baby[] babies; //array created babies = new
I would like to store 2 elements in 1 index of an array.
For example : private static Baby[] babies; //array created
babies = new Baby[4]; //4 indexes
Baby baby1 = new Baby("John",1); Baby baby2 = new Baby("Peter",2); Baby baby3 = new Baby("Peter",3); Baby baby4 = new Baby("Peter",4); babies[0] = baby1; babies[1] = baby2; babies[2] = baby3; babies[3] = baby4;
^ this is the hardcoded way of entering elements into indexes.
I want to get the user input for name and age and to be placed in the array[4]. How do i do that?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
