Monday, February 11, 2008


Table of a Given Number : Java Example

This example explain how to print table of a given number. This is useful example of a java program for the beginners using while loop. We can also use for loop to print table :

Tableexample{
public static void main(String[] args) {
int a=5, b=1;
System.out.println("table of "+a+"= ");
while(b<=10){
int c = a*b;
System.out.println(c);
b = b+1;
}
}
}


Thursday, February 7, 2008


Check a Number : Even or Odd?

A very simple program to find whether a number is odd or even. As we have taken 4 to check whether it is even or not. It is even because when we divide it by 2 then the reminder will be 0.

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

}
}