forked from jsquared21/Intro-to-Java-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise_02_11.java
More file actions
executable file
·24 lines (20 loc) · 851 Bytes
/
Exercise_02_11.java
File metadata and controls
executable file
·24 lines (20 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
(Population projection) Rewrite Programming Exercise 1.11 to prompt the user
to enter the number of years and displays the population after the number of years.
Use the hint in Programming Exercise 1.11 for this program. The population
should be cast into an integer. Here is a sample run of the program:
*/
import java.util.Scanner;
public class Exercise_02_11 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // Create a Scanner object
// Prompt the user to the number of years
System.out.print("Enter the number of years: ");
int years = input.nextInt();
// Calculate population projection
int population = 312032486 + (((31536000 / 7) - (31536000 / 13)
+ (31536000 / 45)) * years);
// Display the results
System.out.println("The population in " + years + " is " + population);
}
}