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 2 of 2

Thread: trouble with nested for(loops)

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default trouble with nested for(loops)

    ok guys, so i have a program due tomorrow that is supposed to print, (just pretend that the lines on the right side are straight)

    +---------+
    | * |
    | /*\ |
    | //*\\ |
    | ///*\\\ |
    | \\\*/// |
    | \\*// |
    | \*/ |
    | * |
    +---------+
    | \\\*/// |
    | \\*// |
    | \*/ |
    | * |
    | * |
    | /*\ |
    | //*\\ |
    | ///*\\\ |
    +---------+

    so far i have this, which will print the top half of the diamond, my question is, how do i essentially flip my code upside down to print the bottom?

    public static void main(String[] args) {
    line();
    triangleTop();
    }

    public static void line() {
    System.out.print("+");
    for (int i = 1; i <= size * 2 + 1; i++) {
    System.out.print("-");
    }
    System.out.print("+");
    System.out.println();
    }

    public static void triangleTop() { // prints the top half of the triangle as
    // well as the lines along either side
    //* of it/*
    for (int i = 1; i <= size; i++) {
    System.out.print("|");
    for (int j = 1; j <= size + 1 - i; j++) {
    System.out.print(" ");
    }
    for (int d = 2; d <= i; d++) {
    System.out.print("/");
    }
    System.out.print("*");
    for (int e = 1; e <= i - 1; e++) {
    System.out.print("\\");
    }
    for (int f = 1; f <= size + 1 - i; f++) {
    System.out.print(" ");
    }
    System.out.print("|");
    System.out.print("\n");
    }
    }
    }

    thanks!


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: trouble with nested for(loops)

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

Similar Threads

  1. Nested loops
    By Rookie in forum Loops & Control Statements
    Replies: 7
    Last Post: May 14th, 2014, 04:11 PM
  2. Re: Nested for loops
    By capt_jaggy in forum Loops & Control Statements
    Replies: 5
    Last Post: March 18th, 2013, 05:21 AM
  3. Nested For Loops
    By javapol in forum Java Theory & Questions
    Replies: 10
    Last Post: February 22nd, 2013, 10:46 PM
  4. Nested for loops
    By Fordy252 in forum Loops & Control Statements
    Replies: 2
    Last Post: December 8th, 2012, 11:43 PM
  5. Using Nested Loops
    By m2msucks in forum Loops & Control Statements
    Replies: 7
    Last Post: November 5th, 2011, 07:05 PM

Tags for this Thread