Easy java question

Danimal1209

Senior member
Nov 9, 2011
355
0
0
Hi guys, I'n my current project I am trying to have one method create an array and another method analyze that array.

So I have:

public static int[] rollDie()
CODE CODE CODE
//This returns an array titled dieResults.

I want to have:
public void outputResults(I want it to accept the dieResults array)

But, I don't know how to make outputResults accept an array. I can't find it online anywhere either.
I want to accept the array so I can count the results and display how many times each number of a die was rolled. I need to have both methods.

Thanks for any input!
 
Last edited:

BrightCandle

Diamond Member
Mar 15, 2007
4,762
0
76
You may want to create a "pure" function with the signature:

Code:
public int[] countResults(int[] rolls) {
  ....
}

Where you just worry about counting 1-6 and map that into a return array with 7 or 6 entries (ignore the 0th or map 1-6 to 0-5).

Follow that with something that prints the results so you separate the logic from how its output. Its more flexible and easier to test.

Code:
public void outputResults(int[] counts) {
....