fielddomino.java

来自「java版的数据结构的完全代码 免费提供了 学习数据结构的请下载」· Java 代码 · 共 44 行

JAVA
44
字号
// Introduced in Chapter 2/** A domino. */public class FieldDomino implements Domino {  /** The number on the left end of the Domino. */  private int left;  /** The number on the right end of the Domino. */  private int right;  /** Initialize the left and right numbers on the Domino. */  public FieldDomino(int left, int right) {    this.left = left;    this.right = right;  }  public void flip() {    int swap = left;    left = right;    right = swap;  }    public int getLeft() {    return left;  }  public int getRight() {    return right;  }  public String toString() {    return left + "-" + right;  }  /** Create a Domino (0-6), print it, flip it, and print it again. */  public static void main(String[] args) {    Domino bone = new FieldDomino(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 + -
显示快捷键?