/* * A class to illustrate the use of some simple functions. */ class FunkyFunctions { public static void main(String[] args) { int firstArg = Integer.parseInt(args[0]); // First command-line argument. int secondArg = Integer.parseInt(args[1]); // Second argument. System.out.println(firstArg + " + 1/" + secondArg + " = " + plusInverse(firstArg, secondArg)); String isOrNot; if (isDivisibleBy(firstArg, secondArg)) { isOrNot = " is "; } else { isOrNot = " is not "; } System.out.println(firstArg + isOrNot + "divisible by " + secondArg); System.out.print("The divisors of " + firstArg + " are "); printDivisors(firstArg); System.out.print("The divisors of " + secondArg + " are "); printDivisors(secondArg); } /* * A function which takes parameters a, b and computes a + 1/b. */ public static double plusInverse(int a, int b) { return a + (double)1/b; } /* * A function which takes parameters a, b and returns a boolean * expressing whether or not a is divisible by b. */ public static boolean isDivisibleBy(int a, int b) { return (a % b == 0); } /* * A function which prints out the positive divisors of its parameter. */ public static void printDivisors(int a) { for (int i = 1; i < a; i++) { if (isDivisibleBy(a, i)) { System.out.print(i + ", "); } } System.out.println(a); } }