内存练习 - 函数调用Q37 E05
从 Main 的 run 方法 开始绘制内存
在每个检查点,检查你画的内存是否跟答案一致
练习 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 public class Point { private int x; private int y; // 此处省略 constructors // 此处省略 getter setters public String description() { // 检查点 1 return "(" + this.x + ", " + this.y + ")"; } public void flip() { x = -y; y = -x; // 检查点 2 } public boolean isOnRight(int x, int y) { boolean onRight = x > this.x; // 检查点 3 return onRight; } public double distanceToOrigin() { return distanceTo(0, 0); } public double distanceTo(int x, int y) { int dx = this.x - x; int dy = this.y - y; // 检查点 4 return Math.sqrt(dx * dx + dy * dy); }}
1 2 3 4 5 6 7 8 9 public class Main { public void run() { Point p = new Point(3, 4); Console.println(p.description()); p.flip(); Console.println(p.isOnRight(4, 3)); Console.println(p.distanceToOrigin()); }}
检查点 1 答案

检查点 2 答案

检查点 3 答案

检查点 4 答案
