Home Answers Viewqa Java-Beginners Check even or odd number.

 
 


ratna rathor
Check even or odd number.
3 Answer(s)      a year ago
Posted in : Java Beginners

How to check given number is even or odd?

View Answers

May 23, 2012 at 5:51 PM


Simple if it is devided by 2 it is even and if not if is Odd


May 23, 2012 at 5:53 PM


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class EvenNumber{

    public static void main(String args[]) throws IOException {

    Sys tem.out.println("Enter the number");
       int num= 0;
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String data = br.readLine();

           num = Integer.parseInt(data);
               if((num %2)==0){
                   System.out.println("Number is Even");

               } else{

                   System.out.println("Number is Odd");

                   }
               }
             }

Description: num is variable which hold the inputted number. BufferReader is used for inputting number. Even numbers are those numbers, which are divisible by 2, and odd numbers are not divisible by 2. if((num %2)==0) is checking the condition of num divisibility. If divisible then it will print even number else odd number.


May 25, 2012 at 12:37 AM


/*
  Even Odd Number Example
  This Java Even Odd Number Example shows how to check if the given
  number is even or odd.
*/

public class FindEvenOrOddNumber {

        public static void main(String[] args) {

                //create an array of 10 numbers
                int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};

                for(int i=0; i < numbers.length; i++){

                        /*
                         * use modulus operator to check if the number is even or odd. 
                         * If we divide any number by 2 and reminder is 0 then the number is
                         * even, otherwise it is odd.
                         */

                         if(numbers[i]%2 == 0)
                                System.out.println(numbers[i] + " is even number.");
                         else
                                System.out.println(numbers[i] + " is odd number.");

                }

        }
}

/*
Output of the program would be<br>
1 is odd number.<br>
2 is even number.<br>
3 is odd number.<br>
4 is even number.<br>
5 is odd number.<br>
6 is even number.<br>
7 is odd number.<br>
8 is even number.<br>
9 is odd number.<br>
10 is even number.<br>
*/









Related Pages:
Check even or odd number.
Check even or odd number.  How to check given number is even or odd?   Simple if it is devided by 2 it is even and if not if is Odd  ...){ System.out.println("Number is Even"); } else
JSTL - check odd/even number - JSP-Servlet
JSTL - check odd/even number  How do i create a JSTL program to generate random numbers and to check whether they are odd/even and print "this is an even (odd) number and it is in between so and so number? e.g. the random number
Even and odd functions in java
); int number; System.out.println("Input any number to check even... have two separate functions for checking either number is even or odd. We...Even and odd functions in java  Even and odd functions in java  
Check whether highest number is even or odd
Check whether highest number is even or odd In this section, you will learn how to check highest number between the two numbers and then determine whether it is odd or even. For this, we have taken two integer variables num1 and num2
Check Even-Odd:-Example
reads a integer value and check weather number is Odd or Even. In this example you will learn how to determine the Even or Odd for the given number entered... Check Even-Odd:-Example     
odd and even
odd and even  how can i make a program of even and odd using case...{ System.out.println(); System.out.println("1 Display Even"); System.out.println("2 Display Odd"); System.out.println("3 Exit"); System.out.print("Choose
Odd Even Transposition Sort In Java
pair off either the odd or even neighboring pairs. Each number (In Processing... Odd Even Transposition Sort In Java   ... In this example we are going to sort integer values of an array using odd even
Calculate sum of even and odd numbers in Java
Calculate sum of even and odd numbers In this section, you will learn how to read the file that contains even and odd numbers and calculate their sum separately. To do this, first of all, we have found all the even and odd numbers from 1
PRIME AND EVEN AND ODD - Java Interview Questions
PRIME AND EVEN AND ODD  how to write prime numbers?i want source code? how to write even numbers? i want source code? how to write odd numbers ?i... + " "; } } } System.out.println(primeNo); } } 2) Following code displays Even and Odd numbers
print the sum of even number from 1 to 100
print the sum of even number from 1 to 100  how to print the sum of even number from 1 to 100 using for loops? Thanks
Check whether the number is palindrome or not
Check whether the number is palindrome or not A palindrome is a word, phrase... direction. Here we are going to check whether the number entered by the user... is by  reversing the digits of the original number and check to see
Check Perfect Number in Java Program
How to Check Perfect Number in Java Program A perfect number is a positive... to the number itself. For example 6 is a perfect number as 1,2 and3 are its divisors... the number from the user and reports whether it is perfect or not. Here
Mysql Mod
you use MOD(a, 3) you get 1 for even numbers and 0 for odd numbers. If you use MOD(a, 2) you get the last digit of the number a. Understand with Example
How to Check Automorphic Number using Java Program
How to Check Automorphic Number using Java Program Automorphic numbers are the numbers whose square ends with the number itself or you can say it is a number... of number 6 at the end. Here we are going to check whether the number entered
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
Check whether the sum of alternate digit of a number is palindrome or not.
Check whether the sum of alternate digit of a number is palindrome... are going to check whether the sum of the alternate digit of a number entered... of this number be 2+4+6 i.e 12) and then check whether this sum is palindrome
prime number
prime number  check prime number using if statement   Java Check Prime Number
prime number
prime number  check prime number using if statement   Java Check Prime Number
Java write even numbers to file
leaving 0 remainder, then it should be an even number and stored in the file. We...Java write even numbers to file In this section, you will learn how to write the even numbers to file. By using the PrintWriter class, you can write any type
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number
print the even numbers between the range 100-200
print the even numbers between the range 100-200  Q ?write an application that print out the even numbers between the range 100-200 ? 1- which aer not divisible by 7 and 5 ? 2- Number of the numbers which are not divisible
prime number
prime number  To check a number entered by user is prime
Number in array
Number in array  How to write a program to check the number that we are entered from keyboard is in the given array
Java number calculation using while loop
); } } } Output: Enter First Number: 4 Enter Second Number: 20 Odd Numbers...Java number calculation using while loop In this tutorial, you will learn how to use while loop to solve certain number calculations. Here is an example
prime number
prime number  To check a number entered by user is prime or not?   Java check prime number import java.util.*; class CheckPrimeNumber { static boolean isPrime(int number){ boolean isPrime=false
odd numbers with loop
odd numbers with loop  get the odd numbers till 100 with for,while loop   Java find odd numbers: class OddNumbers { public static void main(String[] args) { for(int i=1;i<=100;i
prime number
prime number  to check wethere given number is prime or not?  ... { static boolean isPrime(int number){ boolean isPrime=false; int i=(int) Math.ceil(Math.sqrt(number)); while (i>1
check box condition
check box condition  Hai, my application has two check box one for chart and another one for table.when We click chart check box download only..."> <xsl:sort select="count(cell)" data-type="number" order
CHECK WHICH NO IS GREATER IN 4 NO'S
CHECK WHICH NO IS GREATER IN 4 NO'S  MAKE A PROGRAM TO CHECK WHICH NO. IS GREATER IN 4 NO'S IN JAVA ???   **class u...; } } System.out.println("Largest Number is: "+max); } }  
check
updated"); will the above code check if the user has entered value for empcode
write an application that print out the even numbers between the range 100-200
write an application that print out the even numbers between the range 100-200   write an application that print out the even numbers between the range 100-200 ?   The given code accepts the number from 100 to 200
dojo check tree code - Ajax
dojo check tree code  Hi..Boss Thanks for ur site. it helped me so many times.. my problem is while trying to use dojo tree with check boxes.../ and even i tried ur application is in roseindia but it stating an exception FATAL
to read number from user
to read number from user  1)print the positive equivalent of the number 2) check if the no is integer or not 3) find the square root of the number 4) find the cube of the number
Check for number of elements exists between the current position and the limit of a buffer.
Check for number of elements exists between the current position and the limit of a buffer. In this tutorial you will see how to check for existence of any... method returns the number of element available in a buffer. Code
Write a program to list all even numbers between two numbers
Write a program to list all even numbers between two numbers       Java Even Numbers - Even... all the even numbers between two numbers. For this first create a class named
VoIP Keep Your Number
VoIP Keep Your Number          VoIP Keep Your Existing Phone Number Changing your phone service to Lingo VoIP phone service is easy, even better since you can keep
prime number - Java Beginners
: System.out.println("Enter number to check: "); long num=input.nextLong...prime number  this project is to determine if a phone number is a prime number. if the number is a prime number then print a message to the effect
Java Check Permutations of String
Java Check Permutations of String In this tutorial, you will learn how to check whether two strings are permutations of each other. You are all aware of this term Permutation. It refers to the rearranging of a number of objects
Validate ID Number
Validate ID Number   How to validate South African ID Number using java.. I can do it using c# but, when it comes to java i;m clueless please help me   Here is a code that check whether the south African Id is valid
sanity check on key recorder - Java Beginners
sanity check on key recorder  In this code, it records both IE and FireFox keys and converts them to upper case. It also displays any key hit even if the cell is not highlighted. My question is, why does it display this using
Java Number Spiral
which must be a positive odd integer number. And depending on the input value...Java Number Spiral In this tutorial, you will learn how to create a  number spiral. A spiral array is a square arrangement of the first N2 natural
Check for number of elements exists between the current position and the limit of a double type buffer.
Check for number of elements exists between the current position and the limit of a double type buffer. In this tutorial you will see how to check... buffer. The remaining method returns the number of element available in a buffer
Palindrome Number Example in Java
reversing the number we will check whether the given number is palindrome... Palindrome Number Example in Java    ... the palindrome number and how to determine any number is palindrome or not. First of all we
Find out the prime number
Find out the prime number      ... to find out whether a given number is prime or not. Here we have used the 'for loop' statement and given the required condition for a prime number. As we know

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.