How can I make the following Java print ints not doubles pub
How can I make the following Java print ints not doubles?
public class Line {
private Point p1;
private Point p2;
public Line(Point p1, Point p2) {
this.p1 = p1;
this.p2 = p2;
}
public Point getP1() {
return p1;
}
public Point getP2() {
return p2;
}
public String toString() {
return \"[(\" + p1.getX() + \", \" + p1.getY() + \"), (\" + p2.getX() + \", \" + p2.getY() + \")]\";
}
}
Solution
Use p1.getX().intValue()
And in the same way you can use for Y which can be
Use p1.getY().intValue()
The return statement will look like this
return \"[(\" + p1.getX().intValue() + \", \" + p1.getY().intValue() + \"), (\" + p2.getX().intValue() + \", \" + p2.getY().intValue() + \")]\";
