
Even and odd functions in java

Example:
import java.util.*;
public class EvenOddFunction {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
System.out.println("Input any number to check even or odd:");
number = input.nextInt();
evenMethod( number);
oddMethod(number);
}
public static void evenMethod(int n) {
if (n % 2 == 0){
System.out.println("Your number " + n + " is even");
}
}
public static void oddMethod(int n) {
if (n % 2 != 0) {
System.out.println("Your number " + n + " is odd");
}
}
}
Description : Number which is divisible by 2 is called even numbers and which is not divisible by 2 is called odd numbers. Here we have two separate functions for checking either number is even or odd. We are passing number as argument in methods.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.