# [HELP] TRIANGLE!

• July 28th, 2010, 09:05 PM
kramista
[HELP] TRIANGLE!
Code :

```OUTPUT * ** *** **** *****   ***** **** *** ** *   * ** *** **** *****   ***** **** *** ** *```

i have made the two triangles the program goes like this.
FOR LOOP.

Code :

```import java.io.*;   public class NewClass {   public static void main(String[] args) {   for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(" "); } System.out.println(""); for (int i = 1; i <= 5; i++) { for (int j = i; j <= 5; j++) { System.out.print("*"); } System.out.println(" "); }   } }```

• July 28th, 2010, 09:07 PM
kramista
Re: [HELP] TRIANGLE!
• July 28th, 2010, 09:28 PM
aussiemcgr
Re: [HELP] TRIANGLE!
So... whats the question?
• July 28th, 2010, 09:33 PM
kramista
Re: [HELP] TRIANGLE!
whats the for loop of
Code :

``` * ** *** **** *****   ***** **** *** ** *```
• July 28th, 2010, 09:54 PM
copeg
Re: [HELP] TRIANGLE!
No one is going to do your homework for you, whether you need it by tomorrow or not. We may however, help you to learn...what is the expected output, and what are you getting?
• July 28th, 2010, 10:51 PM
helloworld922
Re: [HELP] TRIANGLE!
Hint:

Look at the number of spaces to stars in each line. How do they change from line to line? Also, what are the initial conditions(initial number of spaces/stars)

I'll let you figure out what the relationship is and how to implement these.
• July 28th, 2010, 11:35 PM
kramista
Re: [HELP] TRIANGLE!
Its just an exercise that my brother is telling me. i got no idea so i ask. its a forum though, just asking! :(

thanks helloworld922 but its much better if you tell me the answer.
• July 29th, 2010, 12:10 AM
kramista
Re: [HELP] TRIANGLE!
• July 29th, 2010, 06:42 AM
Darryl.Burke
Re: [HELP] TRIANGLE!
Quote:

Originally Posted by kramista
Its just an exercise that my brother is telling me. i got no idea so i ask. its a forum though, just asking! :(

If that's your small brother, stamp on him. If your big brother, prepare to be stamped on.

And btw we've already heard pretty nearly all the "It's not homework!" disclaimers that have ever been thought of. So here's a challenge for you: come up with something uniquely entertaining and believable*, and I'll guide you till your code is complete.

* Not "I'm teaching a class and need to know this myself' -- that's been used about a gazillion times.

db
• July 29th, 2010, 08:11 AM
JavaPF
Re: [HELP] TRIANGLE!
Tricky! Have you attempted this? Please post what code you have so we can guide you...
• July 29th, 2010, 12:58 PM
helloworld922
Re: [HELP] TRIANGLE!
If it's a personal project, why would it be so urgent?

If you do what I suggested, you should be able to see a very easy pattern to pick out, and then code your program to follow that pattern.

Here's a sample of printing out an isoceles triangle.
Code :

``` * *** ***** *******```

Number of rows? n
number of start spaces? n - 1
number of start starts? 1
how does the number of spaces change from row to row? each successive row has 1 less space
how does the number of stars change from row to row? each successive row gets 2 more spaces

Now, the pseudo-code:

Code Pseudo:

```number of rows = n initial number of stars = 1 initial number of spaces = rows - 1 for every row: print out number of spaces spaces print out number of stars stars decrease number of spaces by 1 increase number of stars by 2 end for loop```

Now you apply this process to your problem.