Ok so I have a problem and it is:
The Fibonacci numbers Fn are defined as follows. F0 is 1, F1 is 1, and
Fi+2 = Fi + Fi+1
i = 0, 1, 2, ... . In other words, each number is the sum of the previous two numbers. The first few Fibonacci numbers are 1, 1, 2, 3, 5, and 8. One place where these numbers occur is as certain population growth rates. If a population has no deaths, then the series shows the size of the population after each time period. It takes an organism two time periods to mature to reproducing age, and then the organism reproduces once every time period. The formula applies most straightforwardly to asexual reproduction at a rate of one offspring per time period. In any event, the green crud population grows at this rate and has a time period of five days. Hence, if a green crud population starts out as 10 pounds of crud, then in five days there is still 10 pounds of crud; in ten days there is 20 pounds of crud, in fifteen days 30 pounds, in twenty days 50 pounds, and so forth. Write a program that takes both the initial size of a green crud population (in pounds) and a number of days as input, and outputs the number of pounds of green crud after that many days. Assume that the population size is the same for four days and then increases every fifth day. Your program should allow the user to repeat this calculation as often as desired.
For my code I have this:
import java.util.*;
public class Assignment36 {
public static void main(String a[]) {
int initialWeight,numberOfDays;
boolean check = true;
Scanner sc = new Scanner(System.in);
while(check)
{
System.out.print("Enter the initial size of a green crud population (in pounds):");
initialWeight = sc.nextInt();
System.out.print("Enter the number of days:");
numberOfDays = sc.nextInt();
System.out.println("The size of the population after "+numberOfDays+" days is "+calculateFinal(initialWeight,numberOfDays)+" pounds.");
System.out.println("Do you want to repeat the calculation with different values? (y/n):");
if(sc.next().toUpperCase().charAt(0)=='N')
check=false;
}
}
public static int calculateFinal(int initialWeight,int numberOfDays)
{
int fLength = numberOfDays/5;
int one=1,two=1,three=0;
for(int i=1;i<=fLength-1;i++)
{
three = one+two;
one = two;
two =three;
}
System.out.println(three);
return initialWeight*three;
}
}
But when I run it nothing is showing up. I'm using Netbeans IDE, maybe that has something to do with it?
An example of what is supposed to show up is something like:
Enter the initial size of a green crud population (in pounds): 10
Enter the number of days: 24
The size of the population after 24 days is 50 pounds.
Do you want to repeat the calculation with different values? (y/n): n
But so far all I'm getting is:
Enter the initial size of a green crud population (in pounds):
If someone can help me with this it would be greatly appreciated. Thank you.