Ask Question

Write the function isOdd () that takes a single parameter n1as input and returns the Boolean value Trueif n is an odd integer and Falseotherwise. Note that the parameter may be any type, but the return value is False whenever it is not an int.

+4
Answers (1)
  1. 1 September, 07:17
    0
    public static boolean isOdd (int n1) {

    if (n1%2==0) {

    System. out. println ("The number is even");

    return true;

    }

    else{

    System. out. println ("The number is odd");

    return false;

    }

    }

    Explanation:

    Using Java program language;

    Declare the method fix the return type to be boolean

    use the modulo operator (%) to check if even since (n%evenNo is equal to 0)

    return true is even or false if not

    See a complete program with user prompt using the scanner class below

    import java. util. Scanner;

    public class TestClock {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter any Integer Number");

    int n = in. nextInt ();

    isOdd (n);

    }

    public static boolean isOdd (int n1) {

    if (n1%2==0) {

    System. out. println ("The number is even");

    return true;

    }

    else{

    System. out. println ("The number is odd");

    return false;

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write the function isOdd () that takes a single parameter n1as input and returns the Boolean value Trueif n is an odd integer and ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers