User-defined Method

The method written by the user or programmer is known as a user-defined method. These methods are modified according to the requirement. How to Create a User-defined Method? Let's create a user defined method that checks the number is even or odd. First, we will define the method.


\begin{lstlisting}
//user defined method
public static void findEvenOdd(int num...
...' is even'');
else
System.out.println(num+'' is odd'');
}
\end{lstlisting}

We have defined the above method named findevenodd(). It has a parameter num of type int. The method does not return any value that's why we have used void. The method body contains the steps to check the number is even or odd. If the number is even, it prints the number is even, else prints the number is odd.