Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: [HELP] TRIANGLE!

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Unhappy [HELP] TRIANGLE!

    OUTPUT
    *
    **
    ***
    ****
    *****
     
    *****
    ****
    ***
    **
    *
     
            *
          **
        ***
      ****       
    *****
     
    *****
      ****
        ***
          **
            *

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

    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(" ");
            }
     
        }
    }

    Please Help me i need it tomorrow

  2. The Following User Says Thank You to kramista For This Useful Post:

    Genky (August 20th, 2012)


  3. #2
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: [HELP] TRIANGLE!

    i need the FOR LOOP of the other two triangles please help

  4. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: [HELP] TRIANGLE!

    So... whats the question?

  5. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: [HELP] TRIANGLE!

    whats the for loop of
            *
          **
        ***
      ****       
    *****
     
    *****
      ****
        ***
          **
            *

  6. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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?
    Last edited by copeg; July 28th, 2010 at 09:57 PM.

  7. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

  8. #7
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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.

  9. #8
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: [HELP] TRIANGLE!

    please help me

  10. #9
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: [HELP] TRIANGLE!

    Quote Originally Posted by kramista View Post
    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

  11. #10
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: [HELP] TRIANGLE!

    Tricky! Have you attempted this? Please post what code you have so we can guide you...
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  12. #11
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.
       *
      ***
     *****
    *******

    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:

    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.

  13. The Following 2 Users Say Thank You to helloworld922 For This Useful Post:

    Genky (August 18th, 2012), JavaPF (July 29th, 2010)

Similar Threads

  1. Triangle Printing - Java Program
    By mparthiban in forum Java Programming Tutorials
    Replies: 1
    Last Post: January 5th, 2012, 10:00 AM
  2. ASCII Triangle
    By physics in forum Loops & Control Statements
    Replies: 1
    Last Post: March 27th, 2010, 06:39 AM
  3. Triangle issues
    By FrEaK in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 24th, 2010, 08:49 AM
  4. Equilateral Triangle Using nested for loop
    By uchizenmaru in forum Loops & Control Statements
    Replies: 2
    Last Post: January 14th, 2010, 10:01 PM
  5. Triangle Question
    By Leeds_Champion in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 29th, 2009, 11:33 PM

Tags for this Thread