Question
Check Whether the number is Even Or odd number.
Example 1:
Enter an Integer number:
12
Entered number is even
Example 2:
Enter an Integer number:
13
Entered number is odd
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
Java
Python
Java
import java.util.Scanner;
public class EvenOdd
{
public static void main(String args[])
{
int num;
System.out.println("Enter an Integer number:");
/*The input provided by user is stored in num*/
Scanner input = new Scanner(System.in);
num = input.nextInt();
/* If number is divisible by 2 then it's an even number else odd number */
if ( num % 2 == 0 )
System.out.println("Entered number is even");
else
System.out.println("Entered number is odd");
}
}
Python
number=int(input("Enter a number:"))
# % gives remainder so here, we are checking
# if a number is completely divisible by 2 or not
if(number % 2== 0):
print(number,"is an even number")
else:
print(number,"is a odd number")