Results 1 to 3 of 3
  1. #1
    1Sserdda is offline Member
    Join Date
    Sep 2009
    Rep Power

    Default variable output is always 0

    Hello all, new the forum. Looking to use this forum for advice/help in writing software for my CSC classes as I work on my software engineering degree.

    Well i hit a speed bump and i cant figure out what going on. I had a to write a program will calculate the length of time to reach a final population or
    final population after a given number of months with user input of the following fields: birth/death rates, initial Pop, population threshold.

    whenever method numBunnies is called it will output 0 no matter the values being passed to it. the calculations are correct, and the program was working at one point, i havent changed anything.

    whenever method numMonths is called will get stuck in an infinite loop. i believe this is because the outputing variable also always seems to equal 0 and thus not knowing when to exit the loop.

    i'll attach the complete java file in txt format, maybe someone can see what im missing.
    Attached Files Attached Files

  2. #2
    1Sserdda is offline Member
    Join Date
    Sep 2009
    Rep Power


    nvm, i figured it out

    BunniesOld = IntPop / threshold;

    in each method need to be cast to a double:

    BunniesOld = (double)IntPop / threshold;

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power

Similar Threads

  1. Can anyone tell me how this output?
    By vysh in forum Advanced Java
    Replies: 16
    Last Post: 05-10-2009, 08:32 PM
  2. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  3. what the outPut
    By alksam in forum Advanced Java
    Replies: 5
    Last Post: 12-25-2008, 01:44 PM
  4. What will be output and why
    By huma in forum Threads and Synchronization
    Replies: 4
    Last Post: 06-26-2008, 10:14 PM
  5. output
    By Camden in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 10:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts