Powered by Blogger.

Even Odd Program in Java



Even Odd Program in Java

This java program finds if a number is odd or even. If the number is divisible by 2 then it will be even, otherwise it is odd. We use modulus operator to find remainder in our program. Odd Even Program in Java

Java programming source code

import java.util.Scanner;

class OddOrEvenDemo
{
   public static void main(String args[])
   {
      int x;
  System.out.println("Enter an integer to check if it is odd or even ");
  Scanner in = new Scanner(System.in);
  x = in.nextInt();

 if ( x % 2 == 0 )
 {    
  System.out.println("This is an even number.");
  }
 else
 {
   System.out.println("This is an odd number.");
  }
 }
}

Output

Enter any Number: 2
This is an even number
Enter any Number: 31
This is an odd number




facebook
google-plus
twitter
pinterest

No comments :

Post a Comment

HTML Tutorial

images

About Sitesbay

This blog is related to Java Tutorial, C++ Tutorial, C Tutorial, Online Earning tips and more in very simple and easy way. Here i will try to give complete idea related to all new technology.

Java Tutorial

Java is Object oriented programming language, It is more secure and high performance language.

C++ Tutorial

C++ is also Object oriented programming language, It is more simple and easy to learn.

 
https://sitesbay.blogspot.com/?utm_medium=d2898efa59afcc0bc411921036e22b767ca37b09