Monday, August 4, 2014

How to find the given number is even or odd in java

How to  find the given number is even or odd in java

  public class TestEx
    {
    public static void main(String args[])
    {
            System.out.println("Enter The Any Number..");
       string number;
     int n=Integer.parseInt(number);
if(n%2==0)
  {
System.out.println("The given number is even "+n);
}
else
{
System.out.println("The given number is odd "+n);
}
}
}

save this program in any drive and goto cmd then compile

   c:> javac TestEx.java
c:> java TestEx
      Enter The Any Number  5
     The given number is odd 5
     again execute program
     Enter The Any Number 8
     The given number is even

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...