How do I print out the value of the method 'center' in this code - Java
-2
public class Point
int x;
int y;
Point(int x, int y)
this.x = x;
this.y = y;
Point center(Point other)
return new Point((x + other.x) / 2, (y + other.y) / 2); // How to print this value?
public void printPoint()
System.out.println("(" + x + "," + y + ")"); //Value of x and y
public class Main
public static void main(String args)
Point p = new Point(1,5);
p.printPoint();
How do I print out the value for "center"?
java
add a comment |
-2
public class Point
int x;
int y;
Point(int x, int y)
this.x = x;
this.y = y;
Point center(Point other)
return new Point((x + other.x) / 2, (y + other.y) / 2); // How to print this value?
public void printPoint()
System.out.println("(" + x + "," + y + ")"); //Value of x and y
public class Main
public static void main(String args)
Point p = new Point(1,5);
p.printPoint();
How do I print out the value for "center"?
java
1
You know how to print thePointcalledp. Callingp.center()returns a point. So callprintPint()on thatPointin exactly the same way you call it onp.
– Joachim Sauer
Nov 14 '18 at 11:17
1
System.out.println(p.center(p).printpoint());
– Jens
Nov 14 '18 at 11:17
1
Thecenterfunction returns aPointobject. ThePointclass have aprintPointfunction. So just call theprintPointfunction on the object thatcenterreturns?
– Some programmer dude
Nov 14 '18 at 11:19
Thanks a lot for the explanation.
– T.M
Nov 14 '18 at 11:40
add a comment |
-2
-2
-2
public class Point
int x;
int y;
Point(int x, int y)
this.x = x;
this.y = y;
Point center(Point other)
return new Point((x + other.x) / 2, (y + other.y) / 2); // How to print this value?
public void printPoint()
System.out.println("(" + x + "," + y + ")"); //Value of x and y
public class Main
public static void main(String args)
Point p = new Point(1,5);
p.printPoint();
How do I print out the value for "center"?
java
public class Point
int x;
int y;
Point(int x, int y)
this.x = x;
this.y = y;
Point center(Point other)
return new Point((x + other.x) / 2, (y + other.y) / 2); // How to print this value?
public void printPoint()
System.out.println("(" + x + "," + y + ")"); //Value of x and y
public class Main
public static void main(String args)
Point p = new Point(1,5);
p.printPoint();
How do I print out the value for "center"?
java
java
edited Nov 14 '18 at 11:15
Some programmer dude
300k25258423
300k25258423
asked Nov 14 '18 at 11:13
T.MT.M
439
439
1
You know how to print thePointcalledp. Callingp.center()returns a point. So callprintPint()on thatPointin exactly the same way you call it onp.
– Joachim Sauer
Nov 14 '18 at 11:17
1
System.out.println(p.center(p).printpoint());
– Jens
Nov 14 '18 at 11:17
1
Thecenterfunction returns aPointobject. ThePointclass have aprintPointfunction. So just call theprintPointfunction on the object thatcenterreturns?
– Some programmer dude
Nov 14 '18 at 11:19
Thanks a lot for the explanation.
– T.M
Nov 14 '18 at 11:40
add a comment |
1
You know how to print thePointcalledp. Callingp.center()returns a point. So callprintPint()on thatPointin exactly the same way you call it onp.
– Joachim Sauer
Nov 14 '18 at 11:17
1
System.out.println(p.center(p).printpoint());
– Jens
Nov 14 '18 at 11:17
1
Thecenterfunction returns aPointobject. ThePointclass have aprintPointfunction. So just call theprintPointfunction on the object thatcenterreturns?
– Some programmer dude
Nov 14 '18 at 11:19
Thanks a lot for the explanation.
– T.M
Nov 14 '18 at 11:40
1
1
You know how to print the
Point called p. Calling p.center() returns a point. So call printPint() on that Point in exactly the same way you call it on p.– Joachim Sauer
Nov 14 '18 at 11:17
You know how to print the
Point called p. Calling p.center() returns a point. So call printPint() on that Point in exactly the same way you call it on p.– Joachim Sauer
Nov 14 '18 at 11:17
1
1
System.out.println(p.center(p).printpoint());
– Jens
Nov 14 '18 at 11:17
System.out.println(p.center(p).printpoint());
– Jens
Nov 14 '18 at 11:17
1
1
The
center function returns a Point object. The Point class have a printPoint function. So just call the printPoint function on the object that center returns?– Some programmer dude
Nov 14 '18 at 11:19
The
center function returns a Point object. The Point class have a printPoint function. So just call the printPoint function on the object that center returns?– Some programmer dude
Nov 14 '18 at 11:19
Thanks a lot for the explanation.
– T.M
Nov 14 '18 at 11:40
Thanks a lot for the explanation.
– T.M
Nov 14 '18 at 11:40
add a comment |
1 Answer
1
active
oldest
votes
2
public static void main(String args)
Point p1 = new Point(1,5);
Point p2 = new Point(3,10);
Point center = p1.center(p2);
center.printPoint();
Thanks! Turamarth
– T.M
Nov 14 '18 at 11:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298902%2fhow-do-i-print-out-the-value-of-the-method-center-in-this-code-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
public static void main(String args)
Point p1 = new Point(1,5);
Point p2 = new Point(3,10);
Point center = p1.center(p2);
center.printPoint();
Thanks! Turamarth
– T.M
Nov 14 '18 at 11:39
add a comment |
2
public static void main(String args)
Point p1 = new Point(1,5);
Point p2 = new Point(3,10);
Point center = p1.center(p2);
center.printPoint();
Thanks! Turamarth
– T.M
Nov 14 '18 at 11:39
add a comment |
2
2
2
public static void main(String args)
Point p1 = new Point(1,5);
Point p2 = new Point(3,10);
Point center = p1.center(p2);
center.printPoint();
public static void main(String args)
Point p1 = new Point(1,5);
Point p2 = new Point(3,10);
Point center = p1.center(p2);
center.printPoint();
answered Nov 14 '18 at 11:16
TuramarthTuramarth
1,19441719
1,19441719
Thanks! Turamarth
– T.M
Nov 14 '18 at 11:39
add a comment |
Thanks! Turamarth
– T.M
Nov 14 '18 at 11:39
Thanks! Turamarth
– T.M
Nov 14 '18 at 11:39
Thanks! Turamarth
– T.M
Nov 14 '18 at 11:39
add a comment |
draft saved
draft discarded
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298902%2fhow-do-i-print-out-the-value-of-the-method-center-in-this-code-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You know how to print the
Pointcalledp. Callingp.center()returns a point. So callprintPint()on thatPointin exactly the same way you call it onp.– Joachim Sauer
Nov 14 '18 at 11:17
1
System.out.println(p.center(p).printpoint());
– Jens
Nov 14 '18 at 11:17
1
The
centerfunction returns aPointobject. ThePointclass have aprintPointfunction. So just call theprintPointfunction on the object thatcenterreturns?– Some programmer dude
Nov 14 '18 at 11:19
Thanks a lot for the explanation.
– T.M
Nov 14 '18 at 11:40