title: Java - Passing 2D array to function
body: <pre><code>-------------------------------------------------------------
  |             | herndon | fairfax | baltimore | centerville |
  -------------------------------------------------------------
  |   herndon   |    0    |    50   |    100    |     20      |
  -------------------------------------------------------------
  |   fairfax   |   50    |    0    |    70     |     110     |
  -------------------------------------------------------------
  |  baltimore  |   100   |    70   |     0     |     200     |
  -------------------------------------------------------------
  | centerville |   20    |    110  |    200    |      0      |
  -------------------------------------------------------------
  </code></pre>
  
  <p>Java - Passing 2D array to function</p>
  
  <p>1) defining a 2D array for distance and populate it -> done ( Its shown in program )</p>
  
  <p>2) defining a city array -> done  ( Its shown in program )</p>
  
  <p>3) ask the user for  soure and destination of the city :</p>
  
  <p>e.g.</p>
  
  <p>Enter from city:<br>
   Enter To city:         </p>
  
  <p>Lets use JOptionPane and Error handling function when user enters cityNames.</p>
  
  <p>4)call function" findDistance "and passsing array of citynames ,array of distances to this function.</p>
  
  <p>5) call function " display" distance &lt;- showing the distances of those cities that was entered by user .</p>
  
  <p>problems i am having :</p>
  
  <p>a)  passing arrays of citynames and array  of distance to findDistance function </p>
  
  <p>(followup #4)</p>
  
  <p>b) passing the argumants to function display.
  (followup #5)</p>
  
  <hr>
  
  <p>here is what i did so Far !</p>
  
  <pre><code>package test;
  
  
  class Test1 {
      public static void main(String[] args) {
          int distances[][] = {{0, 50, 100, 20}, {50, 0, 70, 110}, {100, 70, 0, 200}, {20, 110, 200, 0}}; // step 1
          String CityNames[] = {"herndon", "fairfax", "baltimore", "centerville"};  // step 2
          findDistance(distances); // -&gt;  a . 1st problem , i am having problem to pass citynames and distances to this function.
          // display  ()     // -&gt; b .  2nd problem i am having : i have a  issue to pass the arguments to this function to Display Distances between 2 cities .
      public static void findDistance(String[] names, int[] dist, int[] src) {
          for(int i = 0; i &lt; src.length; i++) {
              // i would like to use JOptioanPane function and error handling
              // instead of system.out.println.
              System.out.println("enter from city" + src[i]);
          }
          for(int i = 0; i &lt; dist.length; i++) {
              System.out.println("enter from city" + dist[i]);
          }
          int i = 0;
          dist[i] = src[i];
          return;
      }
  }
  </code></pre>