Results 1 to 2 of 2
  1. #1
    Dan121 is offline Member
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Exclamation asterisks triangles

    Hi

    i have written a program to display a
    *****
    ****
    ***
    **
    *
    triangle using the code
    Java Code:
                    String stars = "",star="";
    	        for(int count = 0; count < 5; count++) 
    	        {
    	           star=star+"*";
    	           stars = stars + star+System.getProperty("line.separator");
    	        } 
                    return stars;
    but i can't figger out how to display a
    *****
    ****
    ***
    **
    *
    traingle using that code

    any help would be be appreshated.

  2. #2
    erhart is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default

    Try this:

    Java Code:
            String stars = "",star="*****";
            for(int count = 5; count > 0; count--) 
            {
               star=star.substring(0, count);
               stars = stars + star+System.getProperty("line.separator");
            } 
                return stars;

Similar Threads

  1. printing an "E" out of asterisks via strings
    By hokieman07 in forum New To Java
    Replies: 1
    Last Post: 04-08-2008, 05:45 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
  •