Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy printing 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, 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 plus"};
    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 know this is simple but I cannot figure it out

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Column names would have to come first, assuming you want them to only show up once:
    PHP Code:
    for (int i 0columnNames.length; ++i)
    {
        
    System.out.println(columNames[i] + "\t");
    }
    for (
    int j 0numbers.length; ++j)
    {
        for (
    int k 0numbers[j].length; ++k)
        {
            
    System.out.println(numbers[j][k] + "\t");
        }

    If you're using a gui, the JTable itself I believe takes both a String[] and an Object[][] to create the column names and data.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Tags for this Thread

    Posting Permissions

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