Q1 : WRITE A JAVA PROGRAM TO PRINT HOLLOW RIGHT ANGLE TRIANGLE.


Program :
/*
WRITE A JAVA PROGRAM TO PRINT HOLLOW RIGHT ANGLE TRIANGLE
*/
class HollowTriangle{
    public static void main(String[] papan) {
        int height=10;
        for (int row=1 ; row<=height ; row++ ) {
            for (int column=1 ; column<=row ; column++ ) {
                if(row-column == 0 || row==height || column==1)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}

/*

D:\Felight\Basic Java>javac HollowTriangle.java

D:\Felight\Basic Java>java HollowTriangle
*
**
* *
*  *
*   *
*    *
*     *
*      *
*       *
**********

*/


Q2 : PRINT A PYRAMID FILLED WITH ASTERISK.


Program :
/*
PRINT A PYRAMID FILLED WITH ASTERISK
*/
class PyramidFilled{
    public static void main(String[] papan) {
        int base=5;
        for (int row=0 ; row<base ; row++ ) {
            for (int j=0;j<base-row ; j++ ) {
                System.out.print(" ");
            }
            for (int k=0 ;k<=row ;k++ ) {
                System.out.print("* ");
            }
            System.out.println();
        }
    }
}

/*

D:\Felight\Basic Java>javac PyramidFilled.java

D:\Felight\Basic Java>java PyramidFilled
     *
    * *
   * * *
  * * * *
 * * * * *

*/

Q3 : PRINT EMPTY PYRAMID MADE OF ASTERISK.


Program :
class EmptyPyramids{
    public static void main(String[] papan) {
        int row=5;
        int i,j;
        for (i=1 ; i<=row ; i++ ) {
            for (j=i ; j<row ; j++ ) {
                System.out.print(" ");
            }
            for ( j=1 ; j<=(2*i-1) ; j++ ) {
                if(i==row || j==1 || j==(2*i-1))
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
            System.out.println();
        }
    }
}

/*
D:\Felight\Basic Java>javac EmptyPyramids.java

D:\Felight\Basic Java>java EmptyPyramids
    *
   * *
  *   *
 *     *
*********
*/