| | |
printing a table, please help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2009
Posts: 30
Reputation:
Solved Threads: 0
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?
Java Syntax (Toggle Plain Text)
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); } } }
0
#4 Oct 30th, 2009
Java Syntax (Toggle Plain Text)
long pop = 6816330827;
•
•
Join Date: Sep 2009
Posts: 30
Reputation:
Solved Threads: 0
0
#5 Oct 30th, 2009
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?
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.
Java Syntax (Toggle Plain Text)
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.
0
#6 Oct 30th, 2009
Concatenate the string you want to print or use printf.
Java Syntax (Toggle Plain Text)
println(year + " " + population)
![]() |
Other Threads in the Java Forum
- Previous Thread: [JAVA}I am having problem with making Quiz program
- Next Thread: ArrayList null issues...
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows






