By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

Stuck on Population Growth Homework

P: 1
Hello, my homework for computer class says

" In a biology experiment, Cory finds that a sample of
microorganisms doubles in population every 12 hours. He
wants to know how many hours it will take to reach a
certain microorganism population level if he starts with
1000 organisms each time.
WAM (write a method) to receive an integer N representing a desired
organism population level, and determine how many
hours it will be until the population level reaches N or
more organisms."

I can't seem to figure this out at all, the code I have so far reads as follows:

public static int (int X, int Y) {
int size = X;
int hours = 0;
while (size<=Y) {
size * 2;
2 Weeks Ago #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 183 receive an integer N..
The function has to accept only one formal argument.

Expand|Select|Wrap|Line Numbers
  1. public static int (int X, int Y) {
No function name is mentioned.

Expand|Select|Wrap|Line Numbers
  1. while (size<=Y) 
It should not check for equality here. Refer the question:
...level reaches N or more organisms...

Expand|Select|Wrap|Line Numbers
  1. size * 2;
This surely is doing size*2 but isn't updating any value.

See the required changes below:
Expand|Select|Wrap|Line Numbers
  1. public static int fun (int N) {
  2.   int size=1000;
  3.   int hours = 0;
  4.   while (size<N) {
  5.     hours+=12;
  6.     size*=2;
  7.   }
  8.   return hours;
  9. }
2 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.