Advertisement
silviasj

Beehive population2

May 11th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BeehivePopulation {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int population = Integer.parseInt(scanner.nextLine());
  8.         int years = Integer.parseInt(scanner.nextLine());
  9.         int migration = 0;
  10.         int beesBorn = 0;
  11.         int beesDead = 0;
  12.  
  13.  
  14.  
  15.         for (int i = 1; i <= years; i++) {
  16.  
  17.             beesBorn = population  / 10 * 2;
  18.             population = beesBorn + population;
  19.  
  20.             if (i % 5 == 0) {
  21.                migration = population / 50 * 5;
  22.                population = population - migration;
  23.             }
  24.             beesDead = population / 20 * 2;
  25.             population = population - beesDead;
  26.         }
  27.  
  28.         System.out.printf("Beehive population: %d", population);
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement