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 ?

86 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

Thankyou for this wondrous post, I am glad I observed this website on yahoo.
downlodable driver

Reply

Cupper has discovered the source of the infection, but she needs time. downloadallthingsfast.com Search through your available transcripts in this exclusive repository area using search criteria.

Reply

Then I use Synergy as 1) I paid long ago and 2) it is more solid (reliable and featured) than any one other app. downloadnowfreesoftware.com Each 5 spins takes off 1 minute from the next bonus reward time.

Reply

Simply snap headstone photos using your GPS-enabled smartphone camera and fill in the person's details from a desktop computer later on. This link Find new photographers to follow or follow your friends and explore the world through the lens of the Steply community.

Reply

Sudden Unintended Acceleration occurred at the underground parking lot of an apartment complex. Go to website. Find them fast for great coin bonuses and use your coins for paint, playgrounds, landscaping, and more.

Reply

The X disappears after 2sec, to be able to choose another place. downlodable manuals Des Enfants Metronome use 2 color flash lights for beat indication.

Reply

1) Improvements of features:- Main Screen: move points. Get it! Simple little program that helps you practice, drill and quizzes the many Spanish verb conjugations.

Reply

*
*A*
*A*A*

Reply

Or if you want to buy or sell something then just tap MyCity. http://express-touristik.ru Once you select the kid's names, numbers, and cell phone companies you will never have to do it again.

Reply

Or if you want to buy or sell something then just tap MyCity. http://express-touristik.ru Once you select the kid's names, numbers, and cell phone companies you will never have to do it again.

Reply

Or if you want to buy or sell something then just tap MyCity. http://express-touristik.ru Once you select the kid's names, numbers, and cell phone companies you will never have to do it again.

Reply

"Import From Google Docs" has moved to "Google Sync" menu and renamed to "Import Documents". topdownloadsoftwaredatabase.us On re-entering the application you will have the option to resume a saved game provided you have attained the save feature.

Reply

Do you have a registered team on Fantasy Premier League. download driver Select MCSA2 on Windows Server 2003 Part 2 from the App Store for the rest of the exam content - 70-227,70-228,70-351

Reply

As the Civil War was drawing to a close, Lincoln became the first American president to be assassinated. download videos Many more features and improvements will be implemented in the near future.

Reply

Contact, with the touch of a button, each county Emergency Management Agents who determine the travel status and share your feedback with them. link for you Please note: App subscriptions do not include access to subscription-only content on our website.

Reply

Changed default number of available racing tracks for new user profiles from 1 to 3. download videos I'm just a regular guy working odd jobs here and there, taking care of my 7mos old daughter.

Reply

==PRICING==The Newsreel application is free and ad supported. downloadtorrentfromalexa.online Try it out and send us an email or visit our website and leave us a comment.

Reply

: CivilWorks: Part of Your Civil Construction Team - FREE for 30-days. web site! You can print to a Wi-Fi printer or any printer attached to your Mac or PC shared on your home or business network.

Reply
This comment has been removed by the author.
This comment has been removed by the author.
This comment has been removed by the author.

how can i print this using for loop and scanner in java just don't mind the (-)
*****
-****
--***
---**
----*

Reply

how can i print this using for loop and scanner in java just don't mind the (-)
----0
---01
--012
-0123
01234

Reply

From Your Mobile Apps: Tom Swift and His Sky Racer by Victor Appleton. downloadthingsfromnora.pro Then, by having a wireless bluetooth keyboard at hand, I can rate songs by pressing a number key while cooking or working out.

Reply

Each one of the substance you said in post is excessively extraordinary and can be particularly significant. I will recollect it, an obligation of appreciation is all together to share the information keep overhauling, searching forward for more posts.Thanks Who Can Do My Assignment

Reply

I just put a couple of your things depictions through copyscape and no doubt the delineations you are using on your things are the right portrayals that are being used on a wide range of goals on the web. Can you Write my Research Paper

Reply

From Your Mobile Apps: Tom Swift and His Sky Racer by Victor Appleton. downloadthingsfromnora.pro Then, by having a remote bluetooth console nearby, I can rate melodies by squeezing a number key while cooking or working out. Someone Do my Assignment for Me

Reply

Thank You for Sharing Valuable Information. I like this blog and this is very informative.
No.1 Electrical Project Center in Chennai | Electrical Project Center in Velachery

Reply

Good Tips share in this for print a triangle in java with loop.

You can read my written article for getting tips for a good research paper.

Reply

Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
Best Web Designing Institute in Chennai
Best web designing course in chennai
web design classes
PHP Training Center in Chennai
PHP Institutes in Chennai
PHP courses in chennai

Reply

Post a Comment

Note: Only a member of this blog may post a comment.