Results 1 to 4 of 4
  1. #1
    pink_872 is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default A tringle using loops

    Hello everyone, I need to draw a triangle using loops only. The output would be stars in the screen as a triangle

    Output:

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

    Please help me. This is the code:

    public class tri{

    public static void main(String[] args){

    int rows = 4;
    for (int i=1; i<rows;i++){
    for (int k=1; k<rows;k++)
    System.out.print(" ");

    for (int j=1; j<=i*2-1;j++)
    System.out.print("*");

    System.out.println();
    }

    }
    }

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    842
    Rep Power
    6

    Default

    Hi,
    gothru this thread looping problems
    Ramya:cool:

  3. #3
    pink_872 is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    Thank you RamyaSivakanth for you replay, but I meant to be as a pyramid shape like this:

    ....*...
    ..***.
    .*****.
    *******

    Ignore the dots (.).

    Please help.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The key is the logic, and to figure that out, think of what steps you would take to do this on paper. Once you've gone through that, translating the steps into Java is easy.

Similar Threads

  1. these loops...
    By Blaedel in forum New To Java
    Replies: 0
    Last Post: 10-01-2009, 07:59 PM
  2. how to use do while loops
    By mikeitalydz in forum New To Java
    Replies: 32
    Last Post: 09-26-2009, 09:30 PM
  3. nested for loops
    By Implode in forum New To Java
    Replies: 4
    Last Post: 09-01-2009, 09:47 AM
  4. [HELP]Java loops
    By jude113 in forum JCreator
    Replies: 0
    Last Post: 03-06-2009, 04:11 AM
  5. Loops (while do etc)
    By manupr in forum New To Java
    Replies: 1
    Last Post: 01-15-2008, 04:59 AM

Posting Permissions

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