| | |
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...
Views: 165 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool linux list loop map method methods mobile netbeans newbie number object oracle pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






