arraydomino.java
来自「java版的数据结构的完全代码 免费提供了 学习数据结构的请下载」· Java 代码 · 共 42 行
JAVA
42 行
// Introduced in Chapter 2/** A domino. */public class ArrayDomino implements Domino { /** The numbers on the Domino. */ int[] numbers; /** Index of the left number. The other one is the right number. */ int leftIndex; /** Initialize the left and right numbers on the Domino. */ public ArrayDomino(int left, int right) { numbers = new int[] {left, right}; leftIndex = 0; } public void flip() { leftIndex = 1 - leftIndex; } public int getLeft() { return numbers[leftIndex]; } public int getRight() { return numbers[1 - leftIndex]; } public String toString() { return numbers[leftIndex] + "-" + numbers[1 - leftIndex]; } /** Create a Domino (0-6), print it, flip it, and print it again. */ public static void main(String[] args) { Domino bone = new ArrayDomino(0, 6); System.out.println(bone.getLeft() + "-" + bone.getRight()); bone.flip(); System.out.println(bone.getLeft() + "-" + bone.getRight()); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?