// actually not higher order programming at all // and not MSP public class HigherOrder1 { public static void printTableTimesTwo(double x1, double x2, int n) { assert n>1; double x = x1; double delta = (x2-x1)/(double)(n-1); System.out.println("x f(x)"); System.out.printf("%20.10f %20.10f\n", x, x*2); for(int i=0; i<(n-1); ++i) { x += delta; System.out.printf("%20.10f %20.10f\n", x, x*2); } } public static void printTablePlusFour(double x1, double x2, int n) { assert n>1; double x = x1; double delta = (x2-x1)/(double)(n-1); System.out.println("x f(x)"); System.out.printf("%20.10f %20.10f\n", x, x+4); for(int i=0; i<(n-1); ++i) { x += delta; System.out.printf("%20.10f %20.10f\n", x, x+4); } } public static void main(String[] args) { printTableTimesTwo(-5, 5, 11); printTablePlusFour(-5, 5, 11); } }