Even Or Odd Number

12 comments - Post a comment

/* Java Program To Check Whether Number is Even or Odd */

class Even
{
public static void main(String args[])
{
int a = 2;
if((a % 2) == 0)
System.out.print("Number is even");
else
System.out.println("Number is odd");

}
}

/************** OUTPUT **************

Number is even */

 
This Post has 12 Comments Add your own!
darshini - March 3, 2008 at 2:10 PM

need more program

anil - March 29, 2008 at 1:16 PM

You can also write:

if( a & 1 )
System.out.println("Number is odd");
else
System.out.print("Number is even");

amadamala - March 29, 2008 at 1:26 PM

// Here is Another way to do this
class Even
{
public static void main(String args[])
{
int a = 2;
boolean isOdd;
isOdd = isOdd(a);

if(isOdd)
{ System.out.println("Odd Num"); }
else
{ System.out.println("Even Num");
}
}
// Checks whether the num is odd or not
private static boolean isOdd(int a)
{
return (a & 1);
}

}

Adrian - February 9, 2009 at 6:23 PM

Hi....
The program was useful!
I just want to ask..
how about if a program is asking a starting value and and ending value.. Wherein the numbers between them will be displayed..
Please help me..

----adrian

vasanth - August 24, 2009 at 4:01 PM

This May Help U...Try tis too...


public class Even_r_odd
{
public static void main(String args[])
{
int i;
int n[]={1,2,3,4,5,6,7,8,9,10};

System.out.println("Even Nos");
for(i=0;i<=9;i++)
{
if(n[i]%2==0)
{
System.out.println(n[i]);
}
}
System.out.println("Odd Nos");
for(i=0;i<=9;i++)
{
if(n[i]%2!=0)

{

System.out.println(n[i]);
}
}
}

}

dheeraj - August 8, 2011 at 10:14 AM

//odd-even in java

public class oddeven
{
public static void main(String args[])
{
int a=9;
{
if((a%2)==0)
{
System.out.println("The number is even");
}
else
{
System.out.println("The number is odd");
}
}

}
}

Bhupesh Nagar - July 25, 2012 at 3:18 PM

class checkeven
{
public static void main(String[] args)
{

int a = Integer.parseInt(args[0]);
if (a % 2 ==0)
{
System.out.println("number is even");
}
else
{
System.out.println("number is odd");
}
}

}

Bhupesh Nagar - July 25, 2012 at 3:19 PM

class checkeven
{
public static void main(String[] args)
{

int a = Integer.parseInt(args[0]);
if (a % 2 ==0)
{
System.out.println("number is even");
}
else
{
System.out.println("number is odd");
}
}

}

Bhupesh Nagar - July 25, 2012 at 3:22 PM

class checkeven
{
public static void main(String[] args)
{

int a = Integer.parseInt(args[0]);
if (a % 2 ==0)
{
System.out.println("number is even");
}
else
{
System.out.println("number is odd");
}
}

}

Bhupesh Nagar - July 25, 2012 at 3:23 PM

class checkeven
{
public static void main(String[] args)
{

int a = Integer.parseInt(args[0]);
if (a % 2 ==0)
{
System.out.println("number is even");
}
else
{
System.out.println("number is odd");
}
}

}

Bhupesh Nagar - July 25, 2012 at 3:23 PM

class checkeven
{
public static void main(String[] args)
{

int a = Integer.parseInt(args[0]);
if (a % 2 ==0)
{
System.out.println("number is even");
}
else
{
System.out.println("number is odd");
}
}

}

Bhupesh Nagar - July 25, 2012 at 3:24 PM

class checkeven
{
public static void main(String[] args)
{

int a = Integer.parseInt(args[0]);
if (a % 2 ==0)
{
System.out.println("number is even");
}
else
{
System.out.println("number is odd");
}
}

}

Post a Comment