/* Java program that generates a table of roots (e.g., square root, cube root, ** etc.) for each number within a range of integer bases. The range of base ** values and the range of roots are governed by global constants. Each row ** of the table shows the roots of one base value. ** ** Author: R. McCloskey ** Date: September 2025 */ public class RootsTable { private static final int MIN_BASE = 2; private static final int MAX_BASE = 10; private static final int MIN_ROOT = 2; private static final int MAX_ROOT = 6; public static void main(String[] args) { printColHeadings(); printTable(); } public static void printColHeadings() { System.out.print("Base "); for (int j = MIN_ROOT; j <= MAX_ROOT; j = j+1) { System.out.printf("%2d-th ", j); } System.out.println(); System.out.print("---- "); for (int j = MIN_ROOT; j <= MAX_ROOT; j = j+1) { System.out.print("----- "); } System.out.println(); } /* Prints the body of the table. */ public static void printTable() { for (int base = MIN_BASE; base <= MAX_BASE; base = base + 1) { printRow(base); } } /* Prints one row of the table, which shows roots of n, starting ** at the MIN_ROOT-th and going to the MAX_ROOT-th root. */ public static void printRow(int n) { System.out.printf("%3d ", n); for (int k = MIN_ROOT; k <= MAX_ROOT; k = k + 1) { double root = rootOf(n, k); System.out.printf("%5.3f ", root); } System.out.println(); } /* Returns the k-th root of num (which corresponds to num raised to ** the 1/k power). */ public static double rootOf(double num, int k) { return Math.pow(num, 1.0/k); } }