Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-19-2011, 04:30 AM   PM User | #1
tlyn
New to the CF scene

 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
tlyn is an unknown quantity at this point
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
tlyn is offline   Reply With Quote
Old 04-19-2011, 04:08 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
java, tables

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:17 PM.


Advertisement
Log in to turn off these ads.