hello everyone, i am trying to write a code that displays a table with 75 years. each year has to display the world population and the projected population for the following years after that by multiplying the current population by the yearly growth (1.17) but i am running into some issues. first of all, the current population happens to be 6,816,330,827. but when i try to assign a variable to that it says that it is out of range. whyy is this? also i am not sure how and where to put the values for population. this is what i have so far, just the years column 1-75. where would i go from here?

public class WorldPopulation {

	public static void main(String[] args) {

	
		int pop ;
		double growth=1.17;
		{System.out.println("Years     " + "Population     " + "Increase     ");
		
		for (int year=1; year<=75; year++)
		System.out.println(year);
		
		
		
		
	}

}
}

The max value for int is 2147483647, so you will need to use long for that value.

how do i use long??? no matter what i do it keeps giving me errors "token long is an invalid expression"

long pop = 6816330827;

Long is just another primitive data type.

alright thanks! i know i am asking a lot here but i am getting closer. my code and its output are below, but how would i get the population to appear next to the year values, and also get it to repeat all the way down to 75?

public class WorldPopulation {

	public static void main(String[] args) {
		
		long pop=6816330827L;
		long population;
		double rate=1.17;
		{System.out.printf("%s%20s\n", "Year", "Population");
		
		for (int year=1; year<=75; year++)
			
			System.out.println(year);

			
		population = (long)(pop*rate);
		
			System.out.println(population);
		

	
		}
		
		
	}

}

output:

Year Population
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
7975107067

as you can see, its showing up at the bottom.

Concatenate the string you want to print

println(year + " " + population)

or use printf.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.