• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating the triangle

 
Thilina Gunawardane
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey im thilina here....
im very new to here........

i can do the right angle triangle... in ths way
*****
****
***
**
*

bt i hve sme problem wth creating

*******
*****
***
*
ths kind of triangle.....

i need hlp for ths......its nt difficult 1 as i knw....bt i don't get da logic of tht.....
anyway... if any1 can help me wth ..im vry gratefull for tht.........thnx...


thnx alot.....
Regards,
Thilina







 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome Thilina

Try it using for loop.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/UseRealWords
 
Thilina Gunawardane
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnx buddy....i did lyk tht b4 and it worked...bt da triangle i want cme up is the 1 i've given below

i want da triangle of the asterics.....

*****
a***a
aa*aa


sorry for da trouble earlier.......
da code i used is given below....
if any can hlp me wth tht... im vry grtfull thnx..




 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here, fixed it so you can read it easily.
no charge.

 
subodh k kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code will print the output as.

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

 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
subodh k kumar, please note what is says on the "Beginning Java" contents page.
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
It does not favours to anybody simply to hand out an answer; in fact if they simply copy your code and don't understand it, you can hinder their learning.

Don't be annoyed with me, but I have pulled rank and deleted the solution you posted.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thilina Gunawardane, please read this.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are going about your exercise the wrong way. You ought to write down very carefully and very simply what you need to do, with pencil and paper. If you use words with more than one syllable, then it doesn't count as "very simply".
 
Thilina Gunawardane
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm really sorry about that.... I was not aware of the rules(Writing) at that time.....really sorry about it....
So anybody who can help to build this triangle

*****
a***a
aa*aa

i need the triangle with asterics...as i have shown above.......

Appreciate your'll effort....
thank you...
Regards,
Thilina.
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thilina Gunawardane wrote:

*****
a***a
aa*aa

i need the triangle with asterics...as i have shown above.......

Appreciate your'll effort....
thank you...
Regards,
Thilina.


where is your code that you have tried till now for doing this??
 
Naman Patidar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to break the problem in parts. In this case try to think the problem as 2 different triangles, Here is a sample solution :
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd approach it as two parts:

1) printing the correct number of '*' characters on each line
2) spacing them correctly.

You can do either part first. once you have that working, add the second. I'd try and find some relationship between the number of things (spaces or *'s) and the line number (i.e. loop counter) I'm currently on.

 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I earlier wrote: . . . please note what is says on the "Beginning Java" contents page.
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
It does not favours to anybody simply to hand out an answer . . .
Naman Patidar, did you not see that post? I have taken your solution out


And I agree with Fred that such an exercise is much easier if broken into smaller parts.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with the triangle solution you originally posted? Sure it prints out like this:

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

instead of this:

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

But that is easily fixable. Both Fred and Campbell are right about breaking this problem down into smaller parts, when I solve problems like this I like to think in Vertical and Horizontal.

Hunter
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that include lateral thinking?
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. It's still a step-by-step process. I just think it is easier(in this case) to think of how many stars you need to print horizontally then how many rows to print vertically.

Hunter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic