# Help on 2D Multi Table Array

• February 1st, 2011, 03:04 AM
clevel211
Help on 2D Multi Table Array
I need help with my code... my desired out put should be

1 2 3
_______
1|1 2 3
2|2 4 6

can someone help me on how to add the header and the other column at the right side area... thanks!!

Code :

```import java.io.*;   public class Test1 { public static void print_array(int[][] num){   for (int i=1; i<num.length; i++) { for (int j=1; j<num[i].length; j++) System.out.print(" " +num[i][j] + " " ); System.out.println(); } } public static void main(String[] args) throws IOException { BufferedReader act2 = new BufferedReader ( new InputStreamReader( System.in ) ); String row, column; int cols = 0; int rows = 0;   System.out.print("Enter A Desired Number of Column(s): "); column= act2.readLine(); cols= Integer.parseInt( column );   System.out.print("Enter A Desired Number of Row(s): "); row= act2.readLine(); rows= Integer.parseInt( row );   int values[][] = new int[rows+1][cols+1]; int [][] m = new int[rows][];   for (int i=1; i < rows; i++) m[i] = new int[cols]; for (int i=0; i < values.length; i++) for (int j=0; j < values[i].length; j++) values[i][j] = i*j;   System.out.println("Activity #2 Multiplication Table"); print_array(values); } }```
• February 1st, 2011, 03:28 AM
DanBrown
Re: Help on 2D Multi Table Array
Code :

```import java.io.*;   public class Test1 { public static void print_array(int[][] num){   [B] System.out.print(" "); for (int i=1; i<num[0].length; i++) { System.out.print(i+" "); }   System.out.println(); for (int i=1; i<=num[0].length; i++) { System.out.print("___"); }   System.out.println(); [/B]   for (int i=1; i<num.length; i++) { [B] System.out.print(""+i+"|");[/B] for (int j=1; j<num[i].length; j++){ System.out.print(" " +num[i][j] + " " ); } System.out.println(); } } public static void main(String[] args) throws IOException { BufferedReader act2 = new BufferedReader ( new InputStreamReader( System.in ) ); String row, column; int cols = 0; int rows = 0;   System.out.print("Enter A Desired Number of Column(s): "); column= act2.readLine(); cols= Integer.parseInt( column );   System.out.print("Enter A Desired Number of Row(s): "); row= act2.readLine(); rows= Integer.parseInt( row );   int values[][] = new int[rows+1][cols+1]; int [][] m = new int[rows][];   for (int i=1; i < rows; i++) m[i] = new int[cols]; for (int i=0; i < values.length; i++) for (int j=0; j < values[i].length; j++) values[i][j] = i*j;   System.out.println("Activity #2 Multiplication Table"); print_array(values); } }```