Wednesday, February 25, 2015

Hadamard java in a pgm



Hadamard.java

public class Hadamard
{
   public static void main(String[] args)
{     
      int N = Integer.parseInt(args[0]);
      boolean[][] H = new boolean[N][N];

     
      H[0][0] = true;
      for (int n = 1; n < N; n += n)
      {
         for (int i = 0; i < n; i++)
         {
            for (int j = 0; j < n; j++)
            {
               H[i+n][j]   =  H[i][j];
               H[i][j+n]   =  H[i][j];
               H[i+n][j+n] = !H[i][j];
            }
         }
      }
      for (int i = 0; i < N; i++)
      {
         for (int j = 0; j < N; j++)
         {
            if (H[i][j])
            System.out.print("* ");
            else       
            System.out.print(". ");
         }
         System.out.println();
      }
   }
         }

No comments:

Post a Comment