Printing Two Dimensional Array in Special Format
<p>I am working in a small task that allow the user to enter the regions of any country and store them in one array. Also, each time he enters a region, the system will ask him to enter the neighbours of that entered region and store these neighbours.</p>

<p>I did the whole task but I have a small problem:</p>

<p>I could not be able to print each region and its neighbours like the following format: </p>

<pre><code>       Region A: neighbour1 neighbour2 

       Region B: neighbour1 neighbour2 
</code></pre>

<p>For example, let us take USA map. I want to print the result as following:</p>

<pre><code>       Washington D.C: Texas, Florida, Oregon
</code></pre>

<p>and so on.</p>

<p>My code is:</p>

<pre><code>    import java.io.*;
    import java.util.Arrays;
    import java.util.Scanner;
    public class Test7{public static void main(String[] args) {
    Scanner kb = new Scanner(System.in);

    System.out.print("Please enter the number of regions: ");
    int REGION_COUNT = kb.nextInt();
        String[] regionNames = new String[REGION_COUNT]; 
    String[][] regions = new String[REGION_COUNT][2];
    for (int r = 0; r &lt; regions.length; r++) {
        System.out.print("Please enter the name of region #" + (r + 1)
                + ": ");
        regionNames[r]  = kb.next();
        System.out
        .print("How many neighbors for region #" + (r + 1) + ": ");
        if (kb.hasNextInt()) {
            int size = kb.nextInt();
            regions[r] = new String[size];
            for (int n = 0; n &lt; size; n++) {
                System.out.print("Please enter the neighbour #" + (n)
                        + ": ");
                regions[r][n] = kb.next();
            }
        } else
            System.exit(0);
    }

    for (int i = 0; i &lt; REGION_COUNT; i++) {
        System.out.print(regionNames[i] +": ");
    for (int k = 0; k &lt; 2; k++) {
        System.out.print(regions[i][k]+", ");
    }
    System.out.println();
    }
    }
}
</code></pre>

<p>The code works fine but the problem is with printing the result only.
Also, I should use the 2 dimensional array.</p>
