I am trying to output Pascal's triangle with asterisks (\*). This is my code:

```
public static void main(String [] arg)
{
    int n=3;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n-i;j++)
        {
            System.out.print(" ");
        }
        boolean b=true;
        for(int k=0;k<i*2+1;k++)
        {
            if(b)
            {
                System.out.print("*");
                b=false;
            }
            else
            {
                System.out.print(" ");
                b=true;
            }

        }
    }
    System.out.println(" ");
}
}

```

I have rechecked several times and failed to find any error.
Also let me know whether the if-block is implemented correctly.
The following code is not giving the required output as below: 

```
     *  
   *   *  
*    *    * 

```