Monday, 12 September 2011

Preparing table of a number by using loop

This tutorial will teach you the methods of preparing the table of a given number by using loop condition. As we know the loop statements are used to repeat a statement or process multiple times according to a specified condition. Loop checks certain condition and if it finds the condition is valuable then all the statements written under loop are executed. 
Here we will take a number a=25 of which we have to prepare a table. Define the integer a=25 and b=1 as the initial point. Now apply "while" condition of loop and confine b<=10 as we have to make a table of 25. Again define another integer as c=a*b, this will be the result when we multiply 'a' with 'b'. Here we have to multiply 'a' with 'b' up to 10 times like a*1, a*2....................a*9, a*10. So make define b=b+1 as increment operator. 
Now compile and run the program on the command window. 
Here is the code of the prorgram:
class  PreparingTable{
  public static void main(String[] args) {
  int a=25, b=1;
  System.out.println("the table of "+a+"= ");
  while(b<=10){
  int c = a*b;
  System.out.println(c);
  b = b+1;
  }
  }
}
Download this example.
Post a Comment