Java Programming | Drawing a right angled triangle

Introduction

This is a tutorial for drawing a right angled triangle in java. The program is given below that prints the triangle directly. The program is extendable. Go enjoy the program. Lets begin……..

Program for drawing a right angled triangle in java.


// the name of our class its public
public class RightAngledTriangle {
//void main
public static void main (String[] args)
{
//declare int
int i,j;
//for loops
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.print("\n");
}
}
}

Output

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

How does it work

No need to input anything. Directly prints the triangle.

Extending it

The program can be extended by using different symbols instead of ‘*’ in program. Go ahead and extend it…..

Explanation.

  1. Declare the class as public
  2. Add the void main function.
  3. Add two loops and print the star.

At the end.

You learnt creating the Java program for Drawing a right angled triangle. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Join India's Largest Code Learning Community on Uphub.io Get it on Google Play
Sharing options: