title: Java - Creating Different Methods with Arrays
body: <p>I'm trying to make my program write to a file using two methods. It compiles with no errors, but when the file that it wrote to is opened, only coordinates with (0,0) are printed. Its supposed to print 10000 random coordinated from the array. Why does it only print out (0,0) coordinates? Also did I place my return statement in the correct place?</p>
  
  <pre><code>import java.io.*;
  
  public class program
  {
    public static void main (String [] args) throws IOException
    {
  
      int points = 10000, dimension = 2, lengthA = 100;//int variables are declared and initialized
  
      PrintWriter fileOut = new PrintWriter (new FileWriter ("arrayPoints.txt"));
  
      double length [] = new double [dimension];//array for length is declared
      double coordinate [][] = new double [points][dimension];//coordinate array is declared
  
      for (int i = 0; i &lt; points; i++){
        fileOut.println(java.util.Arrays.toString(coordinate[i]));
                        }
        fileOut.close();//writes to file
  
    }//end main method
  
      public static double writeTofile (double length[], double coordinate[][], int points, int dimension, int lengthA)
      {
        int x = 0, y = 0;
        for(int z = 0; z &lt; dimension; z++){//fills the length array with the the set value of lengthA
        length[z] = lengthA;
        }
  
      for(x = 0; x &lt; points; x++){//runs 1000 times to print 1000 data points
        for (y = 0; y &lt; dimension; y++){//runs 2 times to print an x and y coordinate
          coordinate [x][y]= (2 *Math.random() - 1) * length[y];// finds a random number in the range and assiigns it to the coordinate array
        }//end for
      }//end for
      return coordinate[x][y];
    }//main method
  }//program
  </code></pre>
  
  <p>I've changed my code and it compiles. however when you look at the file it printed to, random letters ([D@76f1fad1[D@889ec59...) are seen. Why is this happening? </p>
  
  <pre><code>import java.io.*;
  
  public class program
  {
    public static void main (String [] args) throws IOException
    {
  
      int points = 10000, dimension = 2, lengthA = 100;//int variables are declared and initialized
  
      PrintWriter fileOut = new PrintWriter (new FileWriter ("arrayPoints.txt"));
  
      double length [] = new double [dimension];//array for length is declared
      double coordinate [][] = new double [points][dimension];//coordinate array is declared
  
      writeTofile(length, coordinate, points, dimension, lengthA);
  
      for (int i = 0; i &lt; points; i++){
        fileOut.println(Arrays.toString(coordinate[i]));
                        }
        fileOut.close();//writes to file
  
    }//end main method
  
      public static void writeTofile (double length[], double coordinate[][], int points, int dimension, int lengthA)
      {
        int x = 0, y = 0;
        for(int z = 0; z &lt; dimension; z++){//fills the length array with the the set value of lengthA
        length[z] = lengthA;
        }
  
      for(x = 0; x &lt; points; x++){//runs 1000 times to print 1000 data points
        for (y = 0; y &lt; dimension; y++){//runs 2 times to print an x and y coordinate
          coordinate [x][y]= (2 *Math.random() - 1) * length[y];// finds a random number in the range and assiigns it to the coordinate array
        }//end for
      }//end for
    }//main method
  }//program
  </code></pre>