Ask Question
10 January, 15:00

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. 10 January, 18:03
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers