I want to create a triangle of ' * ' in java?

Submitted 4 years, 6 months ago
Ticket #183
Views 306
Language/Framework Java
Priority Medium
Status Closed

public class Main
{
	public static void main(String[] args) {for (int i=0; i<6; i++)
  {
  for (int j=0; j<i; j++)
  {
  System.out.print("*");
  }
  System.out.println("");
  }
  
       }
	}

I  have this code but it is printing half triangle like shown below

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

I want to print a  full triangle.....

Submitted on Sep 30, 20

Do you mean a Pyramid?? - Unknown 4 years, 6 months ago

yes - Soudhamini 4 years, 6 months ago

ok - Star 4 years, 6 months ago
add a comment

1 Answer

Verified

Triangle programe in java

public class main {

    public static void main(String[] args) {
     for (int i = 0; i < 5; i++) {
          for (int j = 0; j < 5 - i; j++) {
              System.out.print(" ")  
              } for (int k = 0; k <= i; k++)       
              { 
                  System.out.print("* ");    
              }
              System.out.println();
              }
      }
  }

Output

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

Submitted 4 years, 6 months ago


Latest Blogs