Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Counter troubles

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Counter troubles

    /**
    Hey guys im new to java programming and have an assigment to write a code to calculate the current population of a organism.
    My problem is i cannot figure out how use my updated population size, he counter just keeps on calulating the population size of the
    given number . ( Hope this is clear run the program and my problem wil be obvious)
    */


    import java.util.Scanner;

    public class Population
    {
    public static void main(String[] args)
    {
    double popsize;
    double averagepopincrease;
    double days;

    Scanner keyboard = new Scanner(System.in);
    System.out.println("Please enter the number of organisms");
    popsize = keyboard.nextDouble();
    if(popsize < 2)
    System.out.println( "Must be atleast 2 oranisms");

    Scanner keyboard1 = new Scanner(System.in);
    System.out.println("Please enter the population increase as a decimal");
    averagepopincrease = keyboard1.nextDouble();
    if(averagepopincrease <= 0)
    System.out.println( "Average Population increase cannot be a negative number");

    Scanner keyboard2 = new Scanner(System.in);
    System.out.println("Please enter the amount of days you wish to calculate");
    days = keyboard2.nextDouble();

    for( days = 1; days <= 10; days++)
    {
    System.out.println((popsize * averagepopincrease) + popsize);

    }
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Counter troubles

    When posting code, please use the highlight tags to preserve formatting.

    Why are you creating multiple scanners?

    When do you take into account which day it is? When do you actually change the population? You're only using the initial values.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Help with counter controlled while loop please!
    By rockout341 in forum Loops & Control Statements
    Replies: 3
    Last Post: March 15th, 2011, 02:41 PM
  2. Help With Counter
    By Catgroove in forum Java Theory & Questions
    Replies: 7
    Last Post: February 10th, 2011, 08:50 AM
  3. Dice Counter
    By Xxl0n3w01fxX in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 26th, 2011, 11:49 AM
  4. Odd Even Zero Counter?
    By velop in forum Java Theory & Questions
    Replies: 1
    Last Post: February 19th, 2010, 02:13 PM
  5. String counter
    By chkang0130 in forum Algorithms & Recursion
    Replies: 9
    Last Post: December 8th, 2009, 11:56 AM