• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Easy java question

Danimal1209

Senior member
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:
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) {
....
 
Back
Top