Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Triangle Pattern In Java

public class leftTrianlge {
  public static void main(String[] args) {

    // size of the triangle
    int size = 5;
    // loop to print the pattern
    for (int i = 0; i < size; i++) {
      // print column
      for (int j = 0; j <= i; j++) {
        System.out.print("*");
      }
      System.out.println();
    }
  }
}

/*

*
**
***
****
*****

*/

public class rightTrianlge {
  public static void main(String[] args) {

    // size of the triangle
    int size = 5;
    // loop to print the pattern
    for (int i = 0; i < size; i++) {
      // print spaces
      for (int j = 1; j < size - i; j++) {
        System.out.print(" ");
      }
      // print stars
      for (int k = 0; k <= i; k++) {
        System.out.print("*");
      }
      System.out.println();
    }
  }
}

/*

    *
   **
  ***
 ****
*****

*/
Source by www.tutorialstonight.com #
 
PREVIOUS NEXT
Tagged: #Triangle #Pattern #In #Java
ADD COMMENT
Topic
Name
3+5 =