14+ Java Odd-Even Program Examples

This post contains a total of 14+ Hand-Picked Java Odd-Even Program Examples with Source Code. All the Odd-Even programs are made using Java Programming Language.

You can use the source code of these programs for educational purpose with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By Ulyana Sveleba

Made by Ulyana Sveleba. Simple Odd even Program. ( Source )

Number 193750241 is odd

public class Program
{
    public static void main(String[] args) {
        int number = 193750241;
        if(number%2 == 0){
            System.out.println("Number " + number + " is even");
        } else{
            System.out.println("Number " + number + " is odd");
        }
    }
}

2. By BroFar

Made by BroFar. Simple Java Odd Even Program that prints random odd and even numbers from 0 to 26. ( Source )

20 is even
23 is odd
12 is even
21 is odd
0 is even
6 is even
10 is even
5 is odd
17 is odd
3 is odd
import java.util.Random;

public class oddeven { boolean eo(int rc) { 
       if(rc%2 ==0) {
                  System.out.println (rc+ " is even");
                  return true; } else {
                  System.out.println(rc+ " is odd");
                  return false; }
                  }
public static void main(String args[]) {
                  oddeven c = new oddeven();
            for (int i=0;i < 10; i++){
                  Random rand = new Random();
                  int mx = 26;
                  int rn = rand.nextInt(mx); 
                  c.eo(rn);
                  }
         }
}

3. By Lavanya Yadav

Made by Lavanya Yadav. ( Source )

odd
public class oddeve
{
   public static void main (String ar[])
   {
      int a=5;
      if(a%2==1) 
         System.out.println("odd");
      else 
          System.out.println("even");
   }
}

4. By qwerty

Made by qwerty. Enter number to check if its even or odd. ( Source )

43
43 is an odd number
// Enter a number.

import java.util.Scanner;

class Program {

    public static void main(String[] args) {        
        int n = new Scanner(System.in).nextInt();
            
        if(n % 2 == 1)
            System.out.print(n + " is an odd number");
        else
            System.out.print(n + " is an even number");                                             
    }    
}

5. By Riyad Arshad

Made by Riyad Arshad. prints all odd and even from 0 to 10. ( Source )

1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
7 is odd
8 is even
9 is odd
10 is even
public class Program
{
    public static void main(String[] args) {
         int a=1;
        while(a<=10){
            if(a%2==0)
            {
        System.out.println(a + " is even");
            }
            else 
            {
        System.out.println(a + " is odd");
            }
            a+=1;
        }
    }
}

6. By Abdirahman Mohamed Ibrahim

Made by Abdirahman Mohamed Ibrahim. ( Source )

plz enter any number
87
the number you have entered 	87 is odd
import java.util.Scanner;

public class Program
{
    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int num;
    System.out.println("plz enter any number");
    num = input.nextInt();
    if(num % 2 ==0){
    System.out.println("the number you have intered \t"  + num  +"is even");
    }
    else {
    System.out.println("the number you have intered \t" + num+ "is odd");
    }
        
    }
}

7. By arpit dixit

Made by arpit dixit. ( Source )

enter number
424
your entered no. 424 is even
import java.util.Scanner;
public class Program
{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("enter number");
        int input = sc.nextInt();
        final int y = input;
        input%=2;
        if(input==1){
          System.out.println("your entered no."+y+" is odd");  
        }
        else{
           System.out.println("your entered no. "+y+" is even"); 
        }
    }
}

8. By Kara

Made by Kara. Even And Odd Numbers With User Data Input. ( Source )

I want to know Even and Odd Numbers till :23
Odd Numbers :1
Even numbers  :2

Odd Numbers :3
Even numbers  :4

Odd Numbers :5
Even numbers  :6

Odd Numbers :7
Even numbers  :8

Odd Numbers :9
Even numbers  :10

Odd Numbers :11
Even numbers  :12

Odd Numbers :13
Even numbers  :14

Odd Numbers :15
Even numbers  :16

Odd Numbers :17
Even numbers  :18

Odd Numbers :19
Even numbers  :20

Odd Numbers :21
Even numbers  :22

Odd Numbers :23
Total Even Numbers between 1-23 are :11
Total Odd Numbers between 1-23 are :12
import java.util.Scanner;

class MyClass {
    public static void main(String[ ] args) {
        Scanner myVar = new Scanner(System.in);
    int input=myVar.nextInt();//fot int value only
    System.out.print("I want to know Even and Odd Numbers till :"+input);//range of even or odd numbers
       int even=0,odd=0;
        for(int i=1;i<=input;i++)     //changer the value of input if you want know more even or odd numbers
        {
           if (i%2==1)//if i%2==1 true its mean number is odd
    {
           System.out.println ("\nOdd Numbers :"+i);
           odd+=1;
            }
            else
            if(i%2==0)//if i%2==0 true its mean numbers is even 
            {
               System.out.println ("Even numbers  :"+i) ;
               even+=1;
               continue ;
            }
        
        }System.out.println ("Total Even Numbers between 1-"+input+" are :"+even ); //this line will count how many even numbers are there between 1-10
        System.out.println ("Total Odd Numbers between 1-"+input+" are :"+odd ); //this line for counting odd numbers between 1-10 
    }
}

9. By Javier Felipe Toribio

Made by Javier Felipe Toribio. Prints the odd and even numbers in a given range. ( Source )

Print even numbers
42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 

Print odd numbers
43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 

import java.util.function.Function;

public class OddEvenNumbers {

    public static void printNumbers
    (int from, int to,
    Function<Integer,Boolean> checkCondition){

        for(int i=from;i<=to;i++) {
            
            if(checkCondition.apply(i)) {
                System.out.print(i + " ");
            }
            
        }
    }

    public static void main(String[] args) {
    
        int from = 42;
        int to = 89;
        
        Function<Integer,Boolean> isEven =
          (num) -> num % 2 == 0;
          
        Function<Integer,Boolean> isOdd = 
          (num) -> num % 2 != 0;

        System.out.println
          ("Print even numbers");
          
        printNumbers(from,to,isEven);

        System.out.println
          ("\n\nPrint odd numbers");
          
        printNumbers(from,to,isOdd);


    }
}

10. By Atul

Made by Atul. Odd or even using bitwise operators. ( Source )

13
odd
public class Program
{
    public static void main(String[] args) {
      int n=new java.util.Scanner(System.in).nextInt();

    
      if(((n|(01))==n))
      System.out.println ("odd");
      else 
      System.out.println("even");
    }
}

11. By Seyi

Made by Seyi. ( Source )

Enter a number 
353
353 is an odd number 
// Please input a number. 
import java.util.Scanner;

class EvenNumbers {
    public static void main(String[ ] args) {
        Scanner myVar = new Scanner(System.in);
        System.out.println("Enter a number ");       
        int x = myVar.nextInt();
        if (x % 2 == 0 ){System.out.println(x + " is an even number ");} else {System.out.println(x +" is an odd number ");}
        System.out.println ("please give  an update vote if you like the code. ");
    }
}

12. By Adrien Zettl

Made by Adrien Zettl. The program prints the odd and even numbers between a given range. ( Source )

Input range (two integers separated by a comma:)
From 0 to 10
- Odd numbers: 1 3 5 7 9 
- Even numbers: 0 2 4 6 8 10 
import java.util.Scanner;

public class OddEvenNumbers {

    static int from;
    static int to;
    
    /*
    1- Get the range from the user input
    2- Test using /2 retainer
    3- Print the odd numbers
    4- Print the even numbers
    */
    public static void main(String[] args) {
        FromTo();
        OddNumbers();
        System.out.println("");
        EvenNumbers();
    }
    
    // Ask the user to input range
    public static void FromTo() {
        System.out.println("Input range (two integers sperated by a comma:)");
        Scanner sc = new Scanner(System.in);
        // Delete white spaces
        String input = new String(sc.nextLine().replace(" ",""));
        sc.close();
        // Split after finding the comma
        int comma = input.indexOf(",");
        Integer f = Integer.valueOf(input.substring(0,comma));
        Integer t = Integer.valueOf(input.substring(comma+1,input.length()));
        // Test to attribute the smallest number to "from", the biggest to "to"
        from = (f<t)?f:t;
        to = (t>f)?t:f;
        System.out.println("From "+from+" to "+to);
    }
    
    // if number/2 retainer โ‰  0 --> odd
    public static void OddNumbers() {
        System.out.print("- Odd numbers: ");
        for(int i = from; i <= to; i++) {
            if(i % 2 != 0) {
                System.out.print(i + " ");
            }
        }
    }
    
    // if number/2 retainer = 0 --> even
    public static void EvenNumbers() {
        System.out.print("- Even numbers: ");
        for(int j = from; j <= to; j++) {
            if(j % 2 == 0) {
                System.out.print(j + " ");
            }
        }
    }
}

13. By Al Toe

Made by Al Toe. Program to check if a number is even or odd without modulo operator or floor division. ( Source )

533
Odd
import java.util.Scanner;

public class Program
{
    public static void main(String[] args) {
    int numb = new Scanner(System.in).nextInt();
    System.out.print(numb/2*2 == numb ? "Even" : "Odd");
    }
}

14. By Mr.Curious

Made by Mr.Curious. Odd even without any condition. ( Source )

77
77 is a odd no.
import java.util.*;
public class Program
{
    public static void main(String[] args) {
    String a[]={" is a even no."," is a odd no."};
    int n=new Scanner(System.in).nextInt();
     System.out.print(n+a[n%2]);
    }
}

15. By RASHMI SHARMA

Made by RASHMI SHARMA. ( Source )

Evens:
10
290
4
58
10
36
10
Odds:
93
73
63
37
37
373
public class Program
{
    public static void fun(int a[]){
           int i,j=0,k=0;
           int[] even = new int[10], odd= new int[10];
           for(i=a.length-1; i>=0; i--){
           if(a[i] % 2 == 0)
           {
                even[j++] = a[i];
           }
           else{
               odd[k++] = a[i];
           }
           }
           System.out.println("Evens:");
           printArr(even);
           
           System.out.println("Odds:");
           printArr(odd);
           
        }
        
    public static void printArr(int[] arr){
       int i =0;
        for(i=0;i<arr.length;i++){
        if(arr[i] !=0)
           System.out.println(arr[i]);
        }
    }

    public static void main(String[] args) {
        int[] a = {10,373,36,37,10,37,58,04,63,290,10,73,93};
        fun(a);
    }
}