Hi, Why doesn't the array result in a value? The indexes and the value in the first occurrence are passed to the display() method. I can't post to the board if I paste the code in the message, so here's the link to the code. Thanks! http://flashpages.prodigy.net/dwolfing/question.htm
Hi, Douglas. I'm a little confused by what you're trying to do. Here is the code, I had to replace i's and j's with j's and k's, to avoid HTML italicization:
First off, the syntax on your for-loops is incorrect. From the Java Language Specification, "The for statement executes some initialization code, then executes an Expression, a Statement, and some update code repeatedly until the value of the Expression is false." So to print the numbers from 0 to 9,
The name of your method is display(), but it looks like you are not only wanting to display the contents of the array, but also populate it with random numbers. Maybe you could split this population out into another method, and then call display() after the 2D array is loaded? And do you want the random integers that you populate the array with to be from 0 to 6, or 0 to 9? Also, you should cast Math.random() to an int only after you multiply it by something, or you'll always get 0 as a result. We'll be better able to steer you in the right direction if you tell us what you need this class to do, Douglas. Thanks, Art Metzer
Thanks, I was casting the value made by Math.random() to an int which, as you pointed out, always leads to a value of 0! The problem I was having that each occurence after the one passed to the method was 0. So I moved the (int) cast outside the whole calculation. And I'll make it more organized with a calculation method and display method, as you suggested.