how to draw triangle in java code example

Example 1: how to draw a triangle in java

graphics.drawPolygon(new int[] {10, 20, 30}, new int[] {100, 20, 100}, 3);
// Graphics.drawPolygon(x-coordinates, y-coordinates, # of points);

Example 2: how to draw triangle in java

public static void main(String[] args) {
/*
         *
         * *
         * * *
         * * * *
         * * * * *
         * * * * * *
         * * * * * * *   */

     int z = 1;
     while (z<=7){ // z value repeat

         int i = 1;
         while (i <= z){
             System.out.print("* ");
             i++;
         }
             System.out.println();
             z++;
     }
        System.out.println("==============");

        int z2 = 7;
        while (z2 >= 1){ // z value repeat

            int i2 = 1;
            while (i2 <= z2){
                System.out.print("* ");
                i2++;
            }

            System.out.println();
            z2--;
        }

Tags:

Java Example