Unfortunately, the current way you are doing this won't work. You are keeping an Integer for each rabbit. Since the number of rabbits increases rapidly, their won't be a way to hold every rabbit in an array.
Since you only need to know the ages of the rabbits, you can keep variables which represent the number of rabbits at a certain age. As each month passes, all rabbits increase in age and new rabbits are born at age 0.
This way you can keep track of the number of matured rabbits, as well as how many rabbits are in each age group.
The final population would simply be the sum of all the rabbits at different age groups.
Scanner in = new Scanner(new File("src/q22565464/rabbits.dat"));
int numSets = Integer.parseInt(in.nextLine().trim());
for(int curSet = 0; curSet<numSets; curSet++){
int months = Integer.parseInt(in.nextLine().trim());
// Could be converted to an array, left for clarity's sake
long matured = 0;
long age2 = 0;
long age1 = 0;
long age0 = 1;
for(int i = 0; i < months; i++){
// the ages of the rabbits increase with each month
matured += age2;
age2 = age1;
age1 = age0;
age0 = matured;
}
System.out.println("Months: " + months + " Population: " + (matured+age2+age1+age0));
}
in.close();