shape.java
来自「国外的数据结构与算法分析用书」· Java 代码 · 共 33 行
JAVA
33 行
/** A shape with a position. */
public class Shape
{
/** x and y coordinantes of the position of the shape. */
public int x, y;
/** Go to the position newX and newY.
Analysis: Time = O(1) */
public void goPosition(int newX, int newY)
{
x = newX;
y = newY;
}
/** Shift the position of the shape by shiftX and shiftY.
Analysis: Time = O(1) */
public void shift(int shiftX, int shiftY)
{
x = x + shiftX;
y = y + shiftY;
}
/** A string of blanks used to indent nested shapes. */
public static String indent = "";
/** String representation of the position of the shape.
Analysis: Time = O(1) */
public String toString()
{
return indent + " Position: " + x + ", " + y + "\n";
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?