// 10/30/2019 // boolean methods and testing // method overloading import java.util.Scanner; public class BooleanMethods { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // test by calling method several times on diff values System.out.println(25 +" " + isEven(25) + '\n' + 78 + " " + isEven(78) + '\n' + 1 + " "+ isEven(1) + '\n' + 2 + " "+ isEven(2) + '\n' + 0 + " "+ isEven(0) + '\n'); // for (int i = -100; i<250; i++) // System.out.println(i + " " + isEven(i) + '\n'); System.out.println("Enter a number: "); int number = sc.nextInt(); //boolean even = isEven(number); //if (even) if (isEven(number)) System.out.println(number + " is even."); else System.out.println(number + " is odd."); } /** @param num is checked to see if its even * @return true if num is even */ public static boolean isEven(int num){ if (num % 2 == 0) return true; return false; // return num%2==0 ? true : false; } // method overloading -- something has to be // different in the parameter list. public static int sum(int num1, int num2) public static int sum(int num1, int num2, int num3) public static int sum(double num1, double num2) } /*Lab: Write a boolean method called isPrime that * accepts an integer and returns true if the parameter * is a Prime number and false otherwise. * hint: use a loop. * TEST the method by calling it many times from main. */