Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Python code to check whether the number is odd or even using operators

Program to check whether the number is odd or even using operators in Java

Posted on September 25, 2020September 25, 2020

Table of Contents

  • Program to check whether the given number is odd or even using operators in Java
    • Code to check whether the number is odd or even
      • Check whether the given number is odd or even using modular operators
      • Check whether the given number is odd or even using divisional operators
      • Check whether the given number is odd or even using ternary operators
      • Check whether the given number is odd or even using bit wise operators
      • Check whether the given number is odd or even using shift operators

Program to check whether the given number is odd or even using operators in Java

In this tutorial, we will discuss the Program to check whether the number is odd or even using operators in Java

In this post, we are going to learn how to check whether the given number is odd or even using operator in Java language

 

Code to check whether the number is odd or even

Check whether the given number is odd or even using modular operators

Program 1

import java.util.Scanner;
class CheckEvenOddModular{
public static void main (String args[]){

Scanner scan=new Scanner(System.in);
System.out.print("Enter the number fo check odd or even: ");
//ask input from the user
int num=scan.nextInt();
//the input value stored in the variable num 

if(num%2==0)//using modular operator
  System.out.print(num+" is an even number");
else
   System.out.print(num+" is an odd number");
System.out.print("\n");
}
}

When the above code is executed, it produces the following result

case 1

Enter the number to check odd or even: 5679
5679 is an odd number

case 2

Enter the number to check odd or even: 564
564 is an even number

 

Check whether the given number is odd or even using divisional operators

Program 2

import java.util.Scanner;
class CheckEvenOddModular{
public static void main (String args[]){

Scanner scan=new Scanner(System.in);
System.out.print("Enter the number fo check odd or even: ");
//ask input from the user
int num=scan.nextInt();
//the input value stored in the variable num 

if((num/2)*2==num)//using divisional operator
  System.out.print(num+" is a even number");
else
   System.out.print(num+" is a odd number");
System.out.print("\n");
}
}

When the above code is executed, it produces the following resut

case 1

Enter the number to check odd or even: 7531
7531 is an odd number

case 2

Enter the number to check odd or even: 736
736 is an even number

 

Check whether the given number is odd or even using ternary operators

Program 3

import java.util.Scanner;
class CheckEvenOddTernary{
public static void main (String args[]){

Scanner scan=new Scanner(System.in);
System.out.print("Enter the number for check odd or even: ");
//ask input from the user
int num=scan.nextInt();
//the input value stored in the variable num 

String evenOdd=(num%2 ==0)? "even":"odd";//using ternary operator

   System.out.print(num+" is "+evenOdd);
System.out.print("\n");
}
}

When the above code is executed, it produces the following resut

Case 1

Enter the number for check odd or even:432
432 is even

Case 2

Enter the number for check odd or even:4321
4321 is odd

 

Check whether the given number is odd or even using bit wise operators

Program 4

import java.util.Scanner;
class CheckOddEvenbitwise{
public static void main(String args[]){
    Scanner scan=new Scanner(System.in); //create a scanner object for input
System.out.print("Enter the integer number: ");

int num=scan.nextInt();//get input from the user for num1
//using divisional operator

if((num & 1)==0){//using bit wise and operator
  System.out.println(num+" is a Even number");
}else{
 System.out.println(num+" is a Odd number");
}
}
}

When the above code is executed, it produces the following resut

case 1

Enter the integer number: 6756
6756 is a Even number

case 2

Enter the integer number: 1133
1133 is a Odd number

 

Check whether the given number is odd or even using shift operators

Program 5

import java.util.Scanner;
class CheckOddEvenShift{
public static void main(String args[]){
    Scanner scan=new Scanner(System.in); //create a scanner object for input
System.out.print("Enter the integer number: ");
//ask input from the user
int num=scan.nextInt();//get input from the user for num1
//using shift operator

  if((num>>1)<<1==num){
  System.out.println(num+" is a Even number");
}else{
 System.out.println(num+" is a Odd number");
}
}
}

When the above code is executed, it produces the following resut

case 1

Enter the integer number: 100
100 is a Even number

case 2

Enter the integer number: 111
111 is a Odd number

 

Similar post

Java Program to check whether the number is odd or even using operators

C Program to check whether the number is odd or even using operators

C++ Program to check whether the number is odd or even using operators

Python Program to check whether the number is odd or even using operators

 

Suggested post

Data type and variable in Java language

variable types in Java language

Operator in Java language

if statement in Java language

For loop in Java language

Method in Java language

Recursion in Java language

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes