Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args){
- Scanner scanner = new Scanner(System.in);
- int numOrganisms;
- double populationIncrease;
- int daysToMultiply;
- double increase;
- double sumIncrease = 0.0;
- double populationResult;
- System.out.print("Enter the starting number of organism: ");
- numOrganisms = scanner.nextInt();
- System.out.print("Enter the daily increase: ");
- populationIncrease = scanner.nextDouble();
- System.out.println("Enter the numbers of days to multiply: ");
- daysToMultiply = scanner.nextInt();
- if (numOrganisms < 2)
- {
- System.out.println("ERROR");
- System.exit(0);
- }
- else if (populationIncrease < 0)
- {
- System.out.println("ERROR");
- System.exit(0);
- }
- else if (daysToMultiply < 1)
- {
- System.out.println("ERROR");
- System.exit(0);
- }
- for (int i = 0; i <= daysToMultiply; i++)
- {
- increase = numOrganisms * populationIncrease;
- sumIncrease += increase;
- populationResult = numOrganisms * sumIncrease;
- System.out.println("Population for day " + i + ": " + populationResult);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment