Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7523563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:50:20+00:00 2026-05-30T02:50:20+00:00

When I enter input that satisfies everything and doesn’t trigger any of my errors,

  • 0
  1. When I enter input that satisfies everything and doesn’t trigger any of my errors, the program just exits after last input like it is skipping over the for or if loop.

  2. Also after System.out.printf("Enter the name of your second species: "); it won’t allow for any input, it just skips to the next prompt. I’m not sure why that is. The section above it asking for the first species’ info works fine.

import java.util.Scanner;

public class HW2johnson_pp1 {

    public static void main(String args[]) {

        Scanner keyboard = new Scanner(System.in);

        System.out.printf("Please enter the species with the higher" + 
                          " population first\n");
        System.out.printf("Enter the name of your first species: ");
        String Species1 = keyboard.nextLine();
        System.out.printf("Enter the species' population: ");
        int Pop1 = keyboard.nextInt();
        System.out.printf("Enter the species' growth rate: ");
        int Growth1 = keyboard.nextInt();

        System.out.printf("Enter the name of your second species: ");
        String Species2 = keyboard.nextLine();
        System.out.printf("Enter the species' population: ");
        int Pop2 = keyboard.nextInt();
        System.out.printf("Enter the species' growth rate: ");
        int Growth2 = keyboard.nextInt();

        if (Pop2 > Pop1) {
            System.out.printf("The first population must be higher. \n");
            System.exit(0);
        }


        Species input1 = new Species();
        input1.name = Species1;
        input1.population = Pop1;
        input1.growthRate = Growth1;

        Species input2 = new Species();
        input2.name = Species2;
        input2.population = Pop2;
        input2.growthRate = Growth2;

        if ((input1.predictPopulation(1) - input2.predictPopulation(1)) <= 
            (input1.predictPopulation(2) - input2.predictPopulation(2))){

            System.out.printf(Species2 + " will never out-populate " + 
                              Species1 + "\n");
        }
        else {

            for (int i = 0; input2.predictPopulation(i) <= 
                            input1.predictPopulation(i); i++) {

                if (input2.predictPopulation(i) == input1.predictPopulation(i)) {
                    System.out.printf(" will out-populate \n");
                }
            }
        }
    }
}

This for the predictPopulation():

public int predictPopulation(int years)
    {
        int result = 0;
        double populationAmount = population;
        int count = years;
        while ((count > 0) && (populationAmount > 0))
        {
            populationAmount = (populationAmount +
                          (growthRate / 100) * populationAmount);
            count--;
        }
        if (populationAmount > 0)
            result = (int)populationAmount;

        return result;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:50:22+00:00Added an answer on May 30, 2026 at 2:50 am
    1. This is because you never print anything after Species 2 overtakes Species 1, except in the very special case that Species 2 and Species 1 have exactly the same population in some year.

    2. This is because, when you enter Species 1’s growth rate, you enter an integer, and then press Enter. keyboard.nextInt() swallows the integer, but leaves the newline on the input-buffer, so the subsequent keyboard.nextLine() thinks there’s an empty line there waiting for it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<input type=text id=name /> <span id=display></span> So that when user enter something inside #name,will
Problem when I enter any input which has underscore (_) data will store to
I needed to write a script to enter multi-line input to a program (
id like to have an input box that a user can enter a search
I need to create an input form that will allow a user to enter
Quick question... I have an input box that upon key enter, adds the value
I have a date input field that allows the user to enter in a
I have a input that you enter a URL, i basically want to write
I have a date input that requires the user to enter the date in
i need to validate a textfield input that allows two digits after a .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.