How To Print A Triangle In Java Using For Loop


hello guys , i remember what kind of homeworks in java students get at the start so i started to post solutions in this even i had to do this when i was doing java (a diploma) our sir asked us to make a program that prints out a triangle using For Loops so i created my own answer but my sir showed us a different one it doesn't even looks like a triangle but it has the triangle shape but mine is exactly a triangle .

this is my answer , NOTE : the easiest and the best way to print a real triangle





preview :

How To Print A Triangle In Java Using For Loop

this what our sir showed us



preview :

How To Print A Triangle In Java Using For Loop

so what do you choose as triangle ?

54 comments

print the triangle using only two loops, and yes also don't use recursion concept! have a happy coding!

Reply
Anonymous mod

I love my iPad. iPad Air has iOS 7. Overall , my iPad is awesome and it is flawless to me.
Your lesson for printing the triangles are the same way for my iPad's remarks.

Reply

Can You Help Me With This Output?
1
121
12321

Reply

that is not nested loop bro. for 123456789 try this :

public class Test
{
public static void main(String [] args)
{
for (int i=1; i<=9; i++)
{
System.out.println();
for (int j=1; j<=i; j++)
{
System.out.print(j);
}
}
System.out.println();
}
}

I am sorry, I am not doing programming anymore so I don't know how else I could help you :)

Reply

Thank you very much
It really helped :)

Reply

can u help to print * diamond shape in java using for loop

Reply

class Diamond {
public static void main(String[] args) {
for (int i = 1; i < 10; i += 2) {
for (int j = 0; j < 9 - i / 2; j++)
System.out.print(" ");

for (int j = 0; j < i; j++)
System.out.print("*");

System.out.print("\n");
}

for (int i = 7; i > 0; i -= 2) {
for (int j = 0; j < 9 - i / 2; j++)
System.out.print(" ");

for (int j = 0; j < i; j++)
System.out.print("*");

System.out.print("\n");
}
}
}
/*
*
***
*****
*******
*********
*******
*****
***
*
*/

source : *http://www.java2s.com/Tutorial/Java/0080__Statement-Control/PrintoutaDiamond.htm

Reply

hi there do have java code for printing do java in pattern like

D D
D D
D D
D D
like this total DO JAVA

Reply

not like that is mush be like

D\\D
D\\\\\\D
D\\\\\D
D\\\D
D
\ is space

Reply

how to make 'A' out of stars(*)

Reply

please some one help me I also need it

Reply

how to get this psttern

555555
4444
333
22
1

Reply

how to get pascal triangle
1
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

Reply
This comment has been removed by the author.

How to print this output
# # # # #
# # # #
# # #
# #
#

Reply
This comment has been removed by the author.

class Test
{
public static void main(String args[])
{
for(int i=4;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print("#");
}
System.out.print("\n");
}
}
}

Reply

Write a program, which prints stars as triangles
1.your program can print 3 diffrent triangles( left triangle, right triangle and centered triangle)
2. Your program ask the user, which kind of triangles has to be printed
( hint: use switch statment)
3. Your program ask the user, how many rows of stars the user want to print
if the user requires 3 the and left triangles, the out put should be like :

Reply

for (int i=4;i>=1;i--)
{
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}

Reply

for(int i=0;i<5;i+=2)
{
for(int j=0;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}

for (int i=3;i>=0;i-=2)
{
for (int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}

Reply

What about as function for the implementation of the Triangle Classification Algorithm?

Reply

hi guys can you help me draw this shape in for loop....

*
*A*
*A*A*

Reply

can you help me draw pascal tringle without arrey

Reply
This comment has been removed by the author.

for(int j=5;j>0;j--)
{
for(int i=0;i<j;i++)
{
System.out.print(j);
}
System.out.println();
}
}

Reply

for(int i=0;i<3;i++)
{
for(int j=0;j<i*2+1;j++)
{
if(j%2!=0)
System.out.print("A");
else
System.out.print("*");


}
System.out.println();

}

Reply

for (int i=0; i<3; i++)
{
for (int k=0; k<6-i; k++)
{
System.out.print(" ");
}
for (int j=0; j=0; i--)
{
for (int k=6-i; k>0; k--)
{
System.out.print(" ");
}
for (int j=i*2+1; j>0; j--)
{
System.out.print("*");
}
System.out.println("");
}

Reply

Can you please share with output, it will be helpful for us

Reply

how do i get this
-----1-----
----333----
---55555---
--7777777--
-999999999-

Reply

How can i print this

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

Reply

brack to band kaun kare ga munna ache se shikh lo uske baad kisi ko sikana

Reply

can you help me how about this
convert this to java

int a,b;

for(a=1;a<=13;a++)
{
for(b=13;b>=a;b-=2)
{
cout<<"* ";
}
cout<<"\n\n";
}
system("PAUSE");
return 0;

}

Reply

Your site is truly intriguing and motivation to numerous. I'll looking forward for a greater amount of your posts. Keep it up!
Cases Solutions

Reply

Great Information,it has lot for stuff which is informative.I will share the post with my friends.
Marketing Case Study

Reply

can you help me to print this?
*
***
*****
***
*

Reply

Very informative article.Thank you author for posting this kind of article .


http://www.wikitechy.com/view-article/java-program-to-print-floyds-triangle-example



Both are really good,
Cheers,
Venkat

Reply

Very informative article.Thank you author for posting this kind of article .


http://www.wikitechy.com/view-article/java-program-to-print-floyds-triangle-example



Both are really good,
Cheers,
Venkat

Reply

class pattern
{
void main()
{
for(int i=5;i>=0;i--)
{
for (int j=i;j>=1;j--)
{System.out.print(i);
}
System.out.println();
}
}
}

Reply

can you help me print this
1 1
11 11
111 111
1111 1111
1111111111

Reply

Can you please help me print a parallelogram shape

Reply

help with programming assignment
Hello very cool website!! Guy .. Beautiful .. Amazing .. I’ll bookmark your site and take the feeds additionally? I’m satisfied to search out a lot of useful info right here in the post, we’d like develop more strategies on this regard, thanks for sharing. 

Reply

My friend recommended this blog and he was totally right keep up the fantastic work!
Noise Engineering Homework Help

Reply

I’m really impressed with your article, Electric Circuits Electrical Assignment Help
such great & usefull knowledge you mentioned here

Reply

it's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information.

Reply

Article Writing Service
I just put several of your products descriptions through copyscape and it looks like the descriptions you are using on your products are the exact descriptions that are being used on dozens of other sites on the web. I realize it's not fun to write content, but you cannot expect Google to rank your site higher than other websites when you have the exact same content as them. Use a service like contentastic.com or contentrunner.com to rewrite each products description to make your site more unique.

Reply

Dissertation Help
  I loved the way you discuss the topic great work thanks for the share.

Reply

I personally like your post, you have shared good article. It will help me in great deal.
essay writing

Reply
This comment has been removed by the author.

Thankyou for this wondrous post, I am glad I observed this website on yahoo.
check out this

Reply

Thankyou for this wondrous post, I am glad I observed this website on yahoo.
downloadnicethingsblog.top

Reply

Post a Comment