
// RecipsTable.java
// Andrew Davison, ad@coe.psu.ac.th, April 2023

/* Generate a table of the decimal expansions of the 
   reciprocals of the first few integers, and record their
   repeating parts (if any) and lengths.

  Usage:
    > compile RecipsTable.java
    > run RecipsTable
*/


import ConsoleTable.Ct4j;

import org.apache.commons.numbers.fraction.*;


public class RecipsTable
{
  private static final int MAX_DENOM = 30;

  public static void main (String[] args)
                throws Exception
  {
    Ct4j table = new Ct4j();
    table.setHeader("1/n", "Decimal", "Repeating Parts", "Length");
        
    for (int d=2; d < MAX_DENOM; d++) {
      Fraction f = Fraction.of(1, d);
      String rseq = Nut.getRecurringSeq(1, d);
      table.addRow(f.toString(), ""+f.doubleValue(), rseq, ""+rseq.length());
               // all arguments must be strings
    }

    table.printTable();
  }  // end of main()

}  // end of RecipsTable class