grodek118

Population increase

Nov 18th, 2022
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args){
  6.  
  7.        Scanner scanner = new Scanner(System.in);
  8.  
  9.         int numOrganisms;
  10.         double populationIncrease;
  11.         int daysToMultiply;
  12.         double increase;
  13.         double sumIncrease = 0.0;
  14.         double populationResult;
  15.  
  16.         System.out.print("Enter the starting number of organism: ");
  17.         numOrganisms = scanner.nextInt();
  18.         System.out.print("Enter the daily increase: ");
  19.         populationIncrease = scanner.nextDouble();
  20.         System.out.println("Enter the numbers of days to multiply: ");
  21.         daysToMultiply = scanner.nextInt();
  22.  
  23.         if (numOrganisms < 2)
  24.         {
  25.             System.out.println("ERROR");
  26.             System.exit(0);
  27.         }
  28.         else if (populationIncrease < 0)
  29.         {
  30.             System.out.println("ERROR");
  31.             System.exit(0);
  32.         }
  33.         else if (daysToMultiply < 1)
  34.         {
  35.             System.out.println("ERROR");
  36.             System.exit(0);
  37.         }
  38.  
  39.         for (int i = 0; i <= daysToMultiply; i++)
  40.         {
  41.             increase = numOrganisms * populationIncrease;
  42.  
  43.             sumIncrease += increase;
  44.  
  45.             populationResult = numOrganisms * sumIncrease;
  46.  
  47.             System.out.println("Population for day " + i + ": " + populationResult);
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment