// This programs tests an integer input by the user for various // fun properties. // // Notice the use of the different if-else constructs. public class FunWithNumbers { public static void main(String[] args) { int number = 24; isZero(number); System.out.println(number + " has " + numFactors(number) + " factors"); isPrime(number); // isEvenOrOdd(number); // isPosOrNeg(number); // getFactors(number); // nextHailstoneNum(number); } // Determines whether or not the given integer is 0. // // int num - the number to test public static void isZero(int num) { System.out.println("Is " + num + " zero?"); if (num == 0) { System.out.println(num + " is zero!"); } System.out.println("All done!"); } // Computes and returns the number of factors of the given integer. // // int num - the integer whose factors are to be computed public static int numFactors(int num) { int count = 0; // for each integer from 1 to num for (int i = 1; i <= num; i++) { // check for divisibility if (num % i == 0) { // if divisible, add 1 to factor count count++; } } return count; } // Determines whether a given integer is prime. // // int num - the number to test public static void isPrime(int num) { if (numFactors(num) == 2) { System.out.println(num + " is prime!"); } System.out.println("Primeness determined."); } // Determines whether a given integer is even or odd. // // int num - the number to test // Determines whether a given integer is positive or negative. // // int num - the number to test // Determines whether a given integer is a multiple of each single // digit prime number. // // int num - the number to test // Computes the next value after the given value in the /// hailstone sequence. The hailstone sequences is defined // as follows: // - if the input is even, the next value is half the input (n / 2) // - if the input is odd, the next value is three times the input // plus one (3n + 1) // // int num - the number to test }