Odd Even Number
if a number is completely divisible by 2 i.e., the remainder is 0, then given number is an even number, like 2,4,6,8, etc. We can also say that we can divide an even number into 2 equal parts,
Whereas if a number is not completely divisible by 2 i.e., the remainder is not 0, is an odd number like 3, 5,7, etc. We can’t divide an odd number into two equal parts.
How to check whether a given number is Odd or Even?
- first, we will take a number input from the user.
- Now we will check remainder after dividing the given number by 2.
- if the remainder is 0 then the number is even otherwise it’s an odd number.
Java Program to check weather a number is even or odd
package theCodeData;
import java.util.Scanner;
public class OddEven {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// take input from user
System.out.println("Enter the Number");
int n = sc.nextInt();
if(n%2==0)
System.out.println("Even");
else System.out.println("Odd");
}
}
Output
You can also watch this odd even java program video.
146 thoughts on “Odd Even in Java”