Results 1 to 6 of 6

Thread: IsoTriangle help

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    14

    IsoTriangle help

    i have created a program which prompts the user for the size of an isoceles triangle and then displas the triangle with that many lines but according to myy project it alsso have to inclue drawBar() method and Addspace method which prints the space how can i do that

    int size;


    System.out.print("Enter Size: ");
    size = input.nextInt();

    int temp = size;

    for (int i = 1; i <= size; i++){
    for (int j = temp; j > 0; j--){
    System.out.print(" ");
    }

    for(int j = 0; j < i; j++){
    System.out.print("*");
    System.out.print(" ");
    }
    System.out.println();
    temp--;
    }

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: IsoTriangle help

    post your attempt at drawBar() addSpace() and I will help.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    14

    Re: IsoTriangle help

    int size;


    System.out.print("Enter Size: ");
    size = input.nextInt();

    int temp = size;

    drawBar(temp, size);

    }

    public static void drawBar(int temp, int size) {

    for (int i = 1; i <= size; i++){

    for(int j = 0; j < i; j++){
    System.out.print("*");
    System.out.print(" ");
    }

    System.out.println();
    temp--;
    }

    }

    public static void addSpaces (int temp, int size){

    for (int i = 1; i <= size; i++){
    for (int j = temp; j > 0; j--){
    System.out.print(" ");
    }
    }
    }

  4. #4
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: IsoTriangle help

    does the apex of your triangle point up or down?

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    14

    Re: IsoTriangle help

    it points up

  6. #6
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: IsoTriangle help

    I had almost the exact same question on my midterm, the only difference was that we had to make a diamond so we had to make the isometric triangle and then just flip it over again.... I will give you this for now, try out some of your code and then we can help you fix it up more

    I found it best to draw out the asterixs and then look for patterns,
    some key forumulas that I found out (if you havn't found them out already)

    1) the triangle is bounded by a (2*n - 1) by (2*n - 1) square, so that means the last row has (2*n - 1) asterixs
    2) the number of asterixs start at one and increase by two every row, so the number in any row is (2 * row - 1) [this is almost the same idea as the one above]
    3) the number of spaces before and after the asterixs is the same. You only have to output the ones infront. The number of spaces before the asterixs for any row can be obtained by (totalRows - currentRow)

    Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width