Results 1 to 2 of 2
  1. #1
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default Asterisks and looping! surely you have a pritier solution than mine

    My task from my book was to output these:

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

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

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

    I did this, with the following code

    Java Code:
    package chapter_v;
    
    public class TrianglePrintingProgram_5_15 
    {
    	public static void main(String[] args)
    	{
    		String chain = "";
    		
    		for(int i = 1 ; i <= 10 ; i++)
    		{
    			chain = chain + "*";
    			System.out.print(chain);
    			if(chain.length() == i)
    			{
    				System.out.println();
    			}
    			
    		}
    		
    		System.out.println();
    		chain = "**********";
    		for(int i = 10 ; i >= 1 ; i--)
    		{
    			System.out.print(chain);
    			System.out.println();
    			chain = chain.substring(0, chain.length() - 1);
    		}
    		
    		System.out.println();
    		chain = "**********";
    		for(int i = 10 ; i >= 1 ; i--)
    		{
    			System.out.print(String.format("%10s", chain));
    			System.out.println();
    			chain = chain.substring(0, chain.length() - 1);
    		}
    		
    		for(int i = 1 ; i <= 10 ; i++)
    		{
    			chain = chain + "*";
    			System.out.print(String.format("%10s", chain));
    			if(chain.length() == i)
    			{
    				System.out.println();
    			}
    			
    		}
    	}
    }
    I just dont like my solutions that much... I feel there are more elegant looping solutions that produce the same output. I was wondering how you professionals would do this (help me think like a programmer). common, I must of cheated with the formatting for the mirrored counterparts

  2. #2
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default Re: Asterisks and looping! surely you have a pritier solution than mine

    last two didnt represent the product after pasting should be mirrors

Similar Threads

  1. Box of asterisks
    By golf_pro90 in forum New To Java
    Replies: 6
    Last Post: 11-01-2011, 11:53 PM
  2. Someone come resolve this problem of mine, please!!!
    By gabriel landry in forum Advanced Java
    Replies: 19
    Last Post: 11-12-2010, 12:32 PM
  3. Replies: 2
    Last Post: 05-12-2010, 06:48 PM
  4. one works, mine doesn't
    By psychop in forum Java Applets
    Replies: 0
    Last Post: 01-26-2010, 12:36 AM
  5. Patch Application Stupidity (mine!)
    By LoTech in forum New To Java
    Replies: 5
    Last Post: 09-17-2008, 03:57 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
  •