Java For loop !!! printing out values
<p>Write a program that generates a sequence of 20 random die tosses in an array and
that prints the die values, marking only the longest run, like this:
1 2 5 5 3 1 2 4 3 (2 2 2 2) 3 6 5 5 6 3 1
If there is more than one run of maximum length, mark the first one.</p>

<p>I am working on this question and this code works till count the maxCount.
However, I am stuck in printing out the final result which means I am working on the last for loop to print out what the question requires.
But, the result is not what I wanted to get. How can I figure it out?       </p>

<pre><code>import java.util.Random;

public class AA {

public static void main(String[] args) {
    int count = 1;
    int maxCount = 1;
    int runEndsAt = 0;

    // create array
    int[] num = new int[20];
    // create random object
    Random numbers = new Random();
    for (int i = 0; i &lt; 20; i++) {
        num[i] = numbers.nextInt(6) + 1;
        // added 1 b/c it starts from 0
    }

    boolean inRun = false;
    for (int i = 0; i &lt; num.length; i++) {
        if (inRun) {
            if (num[i] != num[i - 1]) {
                /*
                 * System.out.print("|" + count +"|");
                 * System.out.print(") ");
                 */ inRun = false;

            }
            if (inRun) {
                System.out.print("|" + count + "|");
                count++;
            }
        }
        if (!inRun) {
            if (count &gt; maxCount) {
                maxCount = count;
                runEndsAt = i;
            }
            count = 1;
            if (i &lt; 19)
                // comparing index from i to i+1
                if (num[i] == num[i + 1]) {
                System.out.print("( ");
                inRun = true;
                }
        }
    }
    if (inRun) {
        /*
         * System.out.print("|" + count +"|"); System.out.print(" )");
         */ }

    for (int i = 0; i &lt; num.length; i++) {
        if (i == runEndsAt - maxCount) {

            System.out.println("(");

            if (i == runEndsAt) {
                System.out.println(")");

            }
        }
    }
 }
}
</code></pre>