-7

I will give two coordinate points with one set method and I will take them with get method. How can I do this? That's my set method but I can't write a get method for this because it can't return 2 int values. That's my set method

   public void setCoordinates(int x,int y)
   {
       this.x=x;
       this.y=y;
   }

And I must create two points like this:

 public static void main(String[] args)
    {
        Point p1=new Point();
        Point p2=new Point();
        p1.setCoordinates(0,8);
        p2.setCoordinates(5,3);
        System.out.println(p1.getCoordinates()+p2.getCoordinates());
        System.out.println(p1.toString()+" "+p2.toString());
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    This site has a search function. Use it before posting a new question. – Raedwald Mar 12 '16 at 20:20
  • 2
    Please search before asking questions that are likely to be common on this site. A [simple Google search](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=java+return+two+values+from+method+site:http:%2F%2Fstackoverflow.com%2F) turned up almost 400,000 similar questions, and the first 2-5 hits would likely be all you'd need. – Hovercraft Full Of Eels Mar 12 '16 at 20:20
  • @Raedwald This site also has a mark as duplicate function. Use it before posting a new comment. – nhgrif Mar 12 '16 at 20:25
  • I couldn't find the right answer – Timuçin Çiçek Mar 12 '16 at 20:26
  • @nhgrif Someone else beat me to it. My comment *might* educate the OP. – Raedwald Mar 12 '16 at 20:29

1 Answers1

-2

You could make two getters. One for the x coordinate and one for the y coordinate.

Then it's just a matter of typing

System.out.println(p1.getXCoordinate());
System.out.println(p1.getYCoordinate());
Lehren
  • 99
  • 2
  • 11