Go to Top

Thursday 4 August 2011

To say whether a number is even or odd

Question 38 : Write a program in Java to to find whether a number is odd or even :

Java Program :



public class even_or_odd
{
 public static void main(int a)
   {
     int b=a%2;
     if (b==0)
     System.out.println("The number "+a+" is an even one");
     else
     System.out.println("The number "+a+" is an odd one");
    }
} 

1 comment:

  1. Its really helpful for me to understand where we i lost in my previous interview. Thanks.
    If anyone wants to Learn Java in Chennai go to the Besant Technologies which is No.1 Training Institute in Chennai.

    http://www.javatraininginchennai.in

    ReplyDelete

ShareThis