printing in a grid

hi

in my class i have a 2d which implements the random number generator

however at the moment it prints the information out in the form of a sentence

what i want is for the information in the array to be printed out in a table 8 across and 50 down

if anybody could help me with my code iv be very appreciative

thanks

import java.util.Random;

publicclass TwoDimensionArray

{

publicstaticvoid main(String args[])

{

int[][] memoryArray=newint[50][8];

Random randnum =new Random();

for(int i=0;i<50;i++)

{

for(int j=0;j<8;j++)

{

memoryArray[i][j]=randnum.nextInt(32);

}

}

for(int i=0;i<50;i++)

{

for(int j=0;j<8;j++)

{

System.out.println("the ["+i+"]["+j+"]element of the Array is: " + memoryArray[i][j]);

}

}

}

}

[1883 byte] By [johnnysmitha] at [2007-11-27 3:37:24]
# 1
any ideas guys?thanks
johnnysmitha at 2007-7-12 8:40:40 > top of Java-index,Java Essentials,New To Java...
# 2

for(int i=0;i<50;i++) {

for(int j=0;j<8;j++) {

// print the [i][j] element, without a new line

}

// print a new line

}

hunter9000a at 2007-7-12 8:40:40 > top of Java-index,Java Essentials,New To Java...
# 3

hey

thanks for the help

still this problem tho if you could help me resolve i would appreciate it very much

for(int i=0;i<50;i++)

{

for(int j=0;j<8;j++)

{

System.out.print("["+i+"]["+j+"]" + memoryArray[i][j]); //is this how you meant?

}

//how do i insert a new line here?

//iv tried System.out.println;

}

}

johnnysmitha at 2007-7-12 8:40:40 > top of Java-index,Java Essentials,New To Java...
# 4
> //iv tried System.out.println;That's what you use. Try harder.Or post an explanation of why it didn't work in your case.
DrClapa at 2007-7-12 8:40:40 > top of Java-index,Java Essentials,New To Java...
# 5

import java.util.Random;

public class TwoDimensionArray

{

public static void main(String args[])

{

int[][] memoryArray=new int[50][8];

Random randnum = new Random();

for(int i=0;i<50;i++)

{

for(int j=0;j<8;j++)

{

memoryArray[j]=randnum.nextInt(32);

}

}

for(int i=0;i<50;i++)

{

for(int j=0;j<8;j++)

{

System.out.print(" | "+ memoryArray[j]+" -- ");

}

System.out.println("| -|");

}

}

}

jacobnebsa at 2007-7-12 8:40:40 > top of Java-index,Java Essentials,New To Java...
# 6
That looks like it should work, but I can't tell for sure without code formatting. Is there still a problem, or are you just posting your completed code?
hunter9000a at 2007-7-12 8:40:40 > top of Java-index,Java Essentials,New To Java...