in java how do i Write a method named isEven that accepts an int argument. The method should return true if the argument is even, or false otherwise. Also write a program to test your method.

Respuesta :

Answer:

============================================

//Class header definition

public class TestEven {

   

   //Method main to test the method isEven

   public static void main(String args[ ] ) {

       

       //Test the method isEven using numbers 5 and 6 as arguments

       System.out.println(isEven(5));

       System.out.println(isEven(6));

     

   }

   

   //Method isEven

   //Method has a return type of boolean since it returns true or false.

   //Method has an int parameter

   public static boolean isEven(int number){

       //A number is even if its modulus with 2 gives zero

      if (number % 2 == 0){

           return true;

       }

       

       //Otherwise, the number is odd

       return false;

   }

}

====================================================

Sample Output:

=========================================================

false

true

==========================================================

Explanation:

The above code has been written in Java. It contains comments explaining every part of the code. Please go through the comments in the code.

A sample output has also been provided. You can save the code as TestEven.java and run it on your machine.

Methods are collections of named program statements that are executed when called or evoked

The program in Java, where comments are used to explain each line is as follows:

import java.util.*;

public class Main {

   public static void main(String args[ ] ) {

       //This creates a Scanner Object

       Scanner input = new Scanner(System.in);

       //This gets input for the number

       int num = input.nextInt();

       //This calls the function

       System.out.println(isEven(num));

  }

  public static boolean isEven(int num){

      //This returns true, if num is even

      if (num % 2 == 0){

          return true;

      }

      //This returns false, if otherwise

      return false;

  }

}

Read more about methods at:

https://brainly.com/question/20442770