-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldPopulation.java
More file actions
60 lines (53 loc) · 1.56 KB
/
Copy pathWorldPopulation.java
File metadata and controls
60 lines (53 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
This program prints a table showing the world population growth over 300 years.
*/
public class WorldPopulation
{
public static void main(String[] args)
{
final int ROWS = 6;
final int COLUMNS = 7;
int[][] populations =
{
{ 106, 107, 111, 133, 221, 767, 1766 },
{ 502, 635, 809, 947, 1402, 3634, 5268 },
{ 2, 2, 2, 6, 13, 30, 46 },
{ 163, 203, 276, 408, 547, 729, 628 },
{ 2, 7, 26, 82, 172, 307, 392 },
{ 16, 24, 38, 74, 167, 511, 809 }
};
String[] continents =
{
"Africa",
"Asia",
"Australia",
"Europe",
"North America",
"South America"
};
System.out.println(" Year 1750 1800 1850 1900 1950 2000 2050");
// Print population data
for (int i = 0; i < ROWS; i++)
{
// Print the ith row
System.out.printf("%20s", continents[i]);
for (int j = 0; j < COLUMNS; j++)
{
System.out.printf("%5d", populations[i][j]);
}
System.out.println(); // Start a new line at the end of the row
}
// Print column totals
System.out.print(" World");
for (int j = 0; j < COLUMNS; j++)
{
int total = 0;
for (int i = 0; i < ROWS; i++)
{
total = total + populations[i][j];
}
System.out.printf("%5d", total);
}
System.out.println();
}
}