hcfrepeat.java

来自「Java经典例程 从外国一大学计算机教授出版物下载的代码 经典」· Java 代码 · 共 42 行

JAVA
42
字号
import javagently.*;

class HCFRepeat {

  /* The HCF Program      by J M Bishop Aug 1996
   * ===============      Display version July 1999
   *                      updated May 2000
   * Calculates the highest common factor of two integers.
   * Illustrates a while loop.
   */

  HCFRepeat () {
    Display display = new Display("HCF");
    display.println("***** Finding the HCF *****");
    display.prompt("Integer a", 567);
    display.prompt("Integer b", 123);
    int a, b;

    while (true) {
      display.ready("Press ready when data has been entered");
      a = display.getInt("Integer a");
      b = display.getInt("Integer b");
      display.println("a\tb");

      while (a != b) {
        display.println(Stream.format(a,6)+"\t"+Stream.format(b,6));
        if (a > b) {
          a -=b;
        } else {
          b -=a;
        }
      }
      display.println("The HCF is " + a);
      display.ready("Press ready for another data set");
    }
  }

  public static void main (String args []) {
    new HCFRepeat();
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?