Results 1 to 3 of 3
  1. #1
    tlyn is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default how to format data tables

    I am very new to java and need to create a data table that shows the growth statistics of a website for three different age groups over 5 years.

    I have entered the data into three arrays, group13_24, group25_54, and group55plus, but I cannot figure out how to print the data table in the correct format, with column and row headers.

    This is what I have so far for printing out the table:

    String[] columnNames = { "13-24", "25-54", "55 +"};
    int[][] numbers = { group13_24, group25_54, group55plus };


    for (int i = 0; i < numbers.length; i++) {
    for (int j = 0; j < numbers.length; j++) {
    out.format("%10d", numbers[i][0])

    I need my output to look like this:
    13-24 25-54 55+
    ----- ----- -----
    2005:
    2006:
    2007:
    2008:
    2009:

    I have been working on this for a while now but cant seem to figure it out :confused:

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    How about a GUI JTable instead of command-line?

    Is there a particular reason e.g. college homework why you need to print the table in command-line?

    I say that because your data is already in the correct format to be added to a JTable

  3. #3
    tlyn is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default

    Yes its for a project im working on for a class,

    ive gotten a little closer, but I still am having trouble

    int[][] numbers = { group13_24, group25_54, group55plus };

    out.format("%20s%15s%15s\n", "13-24", "25-54", "55+") ;
    out.format("%20s%15s%15s\n", "-----", "-----", "-----");
    out.println();
    for (int i = 0; i < numbers.length; i++) {
    out.format("%20s", numbers[i][0]);
    for (int j = 0; j < numbers.length; j++) {
    out.format("%15s", numbers[j][0]);

    }

Similar Threads

  1. how to get data from more than two tables based on other
    By kishan.java in forum New To Java
    Replies: 1
    Last Post: 03-24-2011, 01:20 PM
  2. Replies: 1
    Last Post: 01-31-2011, 03:38 AM
  3. Replies: 1
    Last Post: 05-20-2010, 04:27 PM
  4. How to use one form to submit data to 2 tables on mysql
    By kwesiaryee in forum New To Java
    Replies: 2
    Last Post: 10-10-2008, 02:41 PM
  5. Replies: 0
    Last Post: 12-24-2007, 10:47 AM

Posting Permissions

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