/* 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 */
Labels: Core Java
Subscribe to:
Post Comments (Atom)
need more program
You can also write:
if( a & 1 )
System.out.println("Number is odd");
else
System.out.print("Number is even");
// 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);
}
}
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
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]);
}
}
}
}
//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");
}
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}
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");
}
}
}