Sunday, June 28, 2015

Triangle Pattern in Java

A simple program that I wrote in Java that will display a triangle pattern on the screen using for loop statements.

I hope you will find my work  useful in a sense the logic of programming is also applied in this simple program.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output


Program Listing

class pattern_one {

  public static void main(String args[]) {
 int a=10;
 int b=1;
 System.out.println("\n\n");
 System.out.print("TRIANGLE PATTERN ONE");
 System.out.println("\n\n");
 for(int i=1; i<=a; i++)
 {
  for (int j=a-1;j>=i; j--)
  {
  System.out.print(" ");
  }
   for (int k=1; k<=b; k++){
    System.out.print("*");
   }
 b++;
System.out.println();
 }
}

  } // End of Program


1 comment:

  1. What do all of the variables represent? That seems unclear to me. (ex. the variable "i" could be representing the spaces before the asterisks)

    ReplyDelete