Results 1 to 2 of 2
  1. #1
    shroomiin is offline Member
    Join Date
    Sep 2009
    Posts
    31
    Rep Power
    0

    Default 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. 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);
    		
    
    	
    		}
    		
    		
    	}
    
    }
    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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Answer deleted due to the OP's multiposting the question.

    OP: why did you repost this same question multiple times? This behavior mainly serve to alienate you from us. Is this your goal?
    Last edited by Fubarable; 10-31-2009 at 01:46 AM.

Similar Threads

  1. Help in Printing
    By kirly in forum Advanced Java
    Replies: 3
    Last Post: 10-03-2011, 03:40 PM
  2. Printing a table with a for loop help
    By shroomiin in forum New To Java
    Replies: 2
    Last Post: 10-31-2009, 01:47 AM
  3. Problem printing inside FOR loop
    By cassysumandak in forum New To Java
    Replies: 1
    Last Post: 10-04-2009, 05:02 PM
  4. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 08:46 PM
  5. Printing Example
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-11-2008, 04:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •