Results 1 to 3 of 3
- 10-31-2009, 12:06 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 31
- Rep Power
- 0
Printing a table with a for loop help
hello, i am trying to write a program that displays the world population for present and the next 75 years based on its annual rate of increase (1.17). below is my code and its output. as you can see i am on the right track but i still cant figure out how to get the population to print next to the year, and also how to get it to repeat all the way down. that big number at the bottom of the list is the world population value that should be next to year 1. any clues?
Java Code: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); } } }
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
- 10-31-2009, 01:12 AM #2
Use the printf method to format each line.
As for why it's last, it's because your println is AFTER the loop. So, only after you output the first 75 values will it appear.Last edited by CodesAway; 10-31-2009 at 01:18 AM.
CodesAway - codesaway.info
writing tools that make writing code a little easier
-
Question multiposted. OP, please cease and desist this behavior.
Similar Threads
-
Help in Printing
By kirly in forum Advanced JavaReplies: 3Last Post: 10-03-2011, 04:40 PM -
Problem printing inside FOR loop
By cassysumandak in forum New To JavaReplies: 1Last Post: 10-04-2009, 06:02 PM -
while-loop stopping on first loop
By davester in forum New To JavaReplies: 6Last Post: 06-26-2009, 09:46 PM -
Printing Help...
By chiragkini in forum AWT / SwingReplies: 1Last Post: 02-17-2009, 07:07 AM -
Printing Example
By Java Tip in forum SWT TipsReplies: 0Last Post: 07-11-2008, 05:41 PM
Bookmarks