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();
  }
}
