File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Array Printing in a Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array Printing in a Class" Watch "Array Printing in a Class" New topic
Author

Array Printing in a Class

Andy Hammersmith
Greenhorn

Joined: Sep 30, 2012
Posts: 13
I made a Galton class to simulate a Galton Board. I am trying to print out a random accurance of what could happen. But i am not able to print out all of the numbers at once. Any suggestions?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

What exactly are you trying to do and what specific problem(s) are you having?
Andy Hammersmith
Greenhorn

Joined: Sep 30, 2012
Posts: 13
I am making a class that will print out the array 'boxcount' to print out from 0 to the nth power. I am not sure how to get it to print out all of them.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Andy Hammersmith wrote:I am making a class that will print out the array 'boxcount' to print out from 0 to the nth power. I am not sure how to get it to print out all of them.


So you don't know how to print out each element of an array?

Is it that you don't know how to do something with each element of an array?

Or is it that you don't know how to print something out?

Because those are the only two things you need to know in order to print out each element of an array, and I see the first is already in your code. Although I don't see the second one there, if this is not your very first Java program ever, you've almost certainly done it (think "Hello World"), so it's not clear to me where your problem lies.
Paul Witten
Ranch Hand

Joined: Oct 10, 2012
Posts: 86
Andy Hammersmith wrote:
public String toString()
{
String dummy = "";
dummy = dummy + " Probability | Galton Board \n";
dummy = dummy + "------------------------------------\n";
dummy = dummy + " " + /*I dont know what to put here*/;
return dummy;
}
}[/code]

Put nothing there. Scrap the method entirely. Output on a line by line basis after the data is generated in the board() method. Use System.out.println() to output and forget concatenating a giant string.

The header to all that can be printed with println() ONCE at the beginning of execution very easily, even in main() to insure it only executes once.

Another suggestion is to call board() so that it will execute. Since there is no call to that method it simply cannot run.

This class will do nothing as a stand-alone class. Nothing at all that I can see. There are methods with no method calls. There is no main().

Or is it not stand alone? There is no way we can see what you're not showing us or describing to us.



 
jQuery in Action, 2nd edition
 
subject: Array Printing in a Class
 
Similar Threads
object-oriented programming
help on Yahtzee
Recursion of Fibonacci Numbers
So far...
Roll the Dice program