A number is called even when it is completely divisible by two and odd if it’s not completely divisible by two. For example number 12 is even number because when you do 12/2 ,
remainder is 0 which means 4 is completely divisible by 2. On the other hand 15 is odd number because 15/2 will result in remainder as 1.

Program Code :

import java.util.Scanner; 
public class TestingEvenOdd{ 
    public static void main(String args[]){               
        
        //scanner to get input from user 
        Scanner scn = new Scanner(System.in); 
        
        System.out.printf("Enter any number : "); 
        int number = scn.nextInt(); 
        if((number %2)==0){ 
            System.out.println("number "+number+" is even number");
        } else{ 
            System.out.println("number "+number+" is odd number"); 
        }  
    }   

Output : 

Enter any number : 15
number 15 is odd number
Next
Newer Post
Previous
This is the last post.
 
Top