Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started