954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Cannot display values of the array

I have two methods. One method was to set location of 2 points x and y. Another method was to copy that location. I used arrays. Well the program compiles but it doesn't display my values properly. Error message says: [D@af9e22. Does anyone know what this is?
Thank you
// MAIN
import java.io.*;
public class Display {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException
{

BufferedReader stdin = new BufferedReader ( new InputStreamReader( System.in ) ); // Initiating a class BufferedReader
// Variables to be implemented in called methods
double x,y;
String temp;

// READING USER INPUT
{
// Reading x value
System.out.println("x value: ");
temp = stdin.readLine();
x = Double.parseDouble( temp ); // convert temp to double using wrapper classes
// Reading y value
System.out.println("y value: ");
temp = stdin.readLine();
y = Double.parseDouble( temp ); // convert temp to double using wrapper classes
}
// Calling methods
Point d = new Point(); // Initiating a class
d.setLocation(x,y); // Set Location method call
d.pointsCopy(d.setLocation(x,y));

System.out.println("Coordinates of points are:" + d.setLocation(x, y));
System.out.println("Copied values of setLocation method are: " + d.pointsCopy(d.setLocation(x,y)));
}

}

// CLASS POINTS
import java.util.Arrays;

public class Point implements Cloneable
{

// instance variables

double points [];
double x;
double y;
/**
* Constructor for objects of class Position
*/
public Point() // This is a no-argument constructor
{
// initialise instance variables to zero
double points [] = {0, 0};
double x = 0;
double y = 0;

}

/**
* setLocation()
* This method sets initial location of a point in 3D
*
* @param x,y,z all floats
* @return none
*/
public double [] setLocation( double x, double y)
{



// allocate space for the array
double points [] = new double [2];

for ( int i=0; i<points.length;i++ )
{
points[i] = i;
}

points [0] = x;
points [1] = y;

return points;
}


public double [] pointsCopy(double points [] )
{
double points1 [] = new double[points.length]; // Allocate space for all elements of array points1

// Copy using System.arrayCopy
System.arraycopy( points, 0, points1, 0, points.length );


return points1;
}


}

grisha83
Junior Poster in Training
70 posts since Sep 2008
Reputation Points: 36
Solved Threads: 0
 

You need to print the elements of the array.

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

Thank you

grisha83
Junior Poster in Training
70 posts since Sep 2008
Reputation Points: 36
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You