CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Threaded View

  1. #1
    Join Date
    Feb 2004
    Posts
    31

    problem displaying patterns correctly using for loops

    problem is i need to write 4 methods to display 4 different designs.

    -all asterisks need to be printed by a single statement:
    Code:
    System.out.print('*')
    - the statement:
    Code:
    System.out.println()
    is used to move to the next line

    -
    Code:
    System.out.print(' ')
    can be used for the last 2 patterns which is what im having trouble with.

    -cant be any other output statements in the program. The last 2 patterns require that each line begin with an appropriate # of blank spaces.

    these are the designs:
    Code:
    a. 
    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********
    
    b.
    
    **********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *
    
    c.
    **********
     *********
      ********
       *******
        ******
         *****
          ****
           ***
            **
             *
    
    d.
             *
            **
           ***
          ****
         *****
        ******
       *******
      ********
     *********
    **********

    I have a and b, just cant get c and d. here is my code.

    Code:
    public class Assignment1
    {
    
       public static void methodA ()
       {
               for (int a=11; a>0; a--)
                  {
                      for (int b=a; b<11; b++)
                          System.out.print("*");
                          System.out.println();
                   }
    
                   
               System.out.println("");
       }
    
       public static void methodB ()
       {
            for (int z=1; z<11; z++)
                  {
                      for (int x=z; x<11; x++)
                          System.out.print("*");
                          System.out.println();
                   }                                                                                               
       }
       public static void methodC ()
       {
          
    
    
       }
    
       public static void methodD ()
       {
         
         
         
    
       }
    
       public static void main (String[] args)
       {
          Assignment1.methodA();
          Assignment1.methodB();
          Assignment1.methodC();
          Assignment1.methodD();
       }
    
    }
    any help with c and d would be great. I keep getting infinite loops
    Attached Files Attached Files
    Last edited by cjard; February 4th, 2005 at 04:45 AM. Reason: c and d dont appear correctly because of the way html works.. putting it in a php or code block preserves the leading spaces (as if it were code)

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

Featured