Bingo Table program in java with Explanation

import java.io.*;                       /*importing package io*/
class Bingo                            
 {
  public static void main(String args[]) throws IOException  /*main method from which the program execution starts*/
    {
    int n,i,j,k=1,l=0;
    int a[][];
    System.out.println("enter n");          
    DataInputStream din=new DataInputStream(System.in);  /*class present in io package*/
    n=Integer.parseInt(din.readLine());
    a=new int[20][20];
    int mid=n/2;    
     for(l=0;l<mid+1;l++)
     {
       for(i=l,j=l;j<n-l;j++)
        {
        a[i][j]=k;     /*This loop controls elements which are in ascending order from left to right*/
        k++;
        }
       for(j=n-l-1,i=1+l;i<n-l;i++)
        {
        a[i][j]=k;     /*This loop controls elements which are in ascending order from top to bottom*/
        k++;                                                                
        }
       for(i=n-l-1,j=n-2-l;j>=0+l;j--)
        {
        a[i][j]=k;     /*This loop controls elements which are in ascending order from right to left*/
        k++;
        }
       for(j=l,i=n-l-2;i>l;i--)
        {
        a[i][j]=k;    /*This loop controls elements which are in ascending order from bottom to top*/
        k++;
        }
     }
    for(i=0;i<n;i++)  /*This block is for printing the elements*/
      {
Bingo-Table-Program-with-Explanation       for(j=0;j<n;j++)
       {
        System.out.print(" "+a[i][j]);
       }
       System.out.print("\n");
     }
   }
}

This is the solution for the bingo table program in java
For any doubts in this program,let me know through comments...
Thanks.......
Share on Google Plus
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment