/**
 * NumberAnalyzer.java
 *
 * Demonstrates the use of if and if-else statements to analyze properties
 * of a number input by the user.
 *
 * Computer Science S-111
 */

import java.util.Scanner;

public class NumberAnalyzer {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        System.out.print("Enter an integer: ");
        int num = console.nextInt();

        // This approach is less than ideal,
        // because it uses redundant conditions.
        // It's better to use an if-else statement,
        // as shown in the code that follows.
        // 
        // if ((num % 2) == 0) {
        //    System.out.println(num + " is even.");
        // }
        //
        // if ((num % 2) != 0) {
        //     System.out.println(num + " is odd.");
        // }
                
        // if num is even, say so.
        if ((num % 2) == 0) {
            System.out.println(num + " is even.");
        } else {
            System.out.println(num + " is odd.");
        }
                
        // In this approach, if a number if divisible by
        // both 3 and 5, we'll only be told that it is
        // divisible by 3, because the if statements are
        // part of the same if-else if statement.
        if (num % 3 == 0) {
            System.out.println(num + " is divisible by 3.");
        } else if (num % 5 == 0) {
            System.out.println(num + " is divisible by 5.");
        } else {
            System.out.println(num + " is divisible by " +
              "neither 3 nor 5.");
        }
                
        // In this approach, if a number if divisible by
        // both 3 and 5, we'll be told that it is
        // divisible by both numbers, because the if
        // statements are independent of each other.
        if (num % 3 == 0) {
            System.out.println(num + " is divisible by 3.");
        }
        if (num % 5 == 0) {
            System.out.println(num + " is divisible by 5.");
        }
        // We could also use this condition:
        // !(num % 5 == 0 || num % 3 == 0)
        if (num % 5 != 0 && num % 3 != 0) {
            System.out.println(num + " is divisible by " +
              "neither 3 nor 5.");                        
        }
    }
}
