jeudi 5 novembre 2015

Printing out a rhombic pattern in java with "for" loop

Vote count: 0

I am having a hard time doing a school exercise in Java. We are asked to print out this pattern:

+++++++++++++++++++++++++++++++++++++++++++++
 +++++++  +++++++  +++++++  +++++++  +++++++ 
  +++++    +++++    +++++    +++++    +++++  
   +++      +++      +++      +++      +++   
    +        +        +        +        +    
   +++      +++      +++      +++      +++   
  +++++    +++++    +++++    +++++    +++++  
 +++++++  +++++++  +++++++  +++++++  +++++++ 
+++++++++++++++++++++++++++++++++++++++++++++
 +++++++  +++++++  +++++++  +++++++  +++++++ 
  +++++    +++++    +++++    +++++    +++++  
   +++      +++      +++      +++      +++   
    +        +        +        +        +    
   +++      +++      +++      +++      +++   
  +++++    +++++    +++++    +++++    +++++  
 +++++++  +++++++  +++++++  +++++++  +++++++ 
+++++++++++++++++++++++++++++++++++++++++++++
 +++++++  +++++++  +++++++  +++++++  +++++++ 
  +++++    +++++    +++++    +++++    +++++  
   +++      +++      +++      +++      +++   
    +        +        +        +        +    
   +++      +++      +++      +++      +++   
  +++++    +++++    +++++    +++++    +++++  
 +++++++  +++++++  +++++++  +++++++  +++++++ 
+++++++++++++++++++++++++++++++++++++++++++++

I can do a triangle, or an hourglass shape,but I can't get it to repeat horizontally.

This is what I have up to now:

    int a = 9;
    char b = '+';
    char c = ' ';

    int i_buffer = a;
    int i_leer = 1;
    for( int i = 0; i < a; i++ ){

        for( int z = i_buffer; z > 0; z--)
        System.out.print( b );

    System.out.println();

    i_buffer = i_buffer - 2;
    if( i_buffer < 0 )
        break;

        for( int z = i_leer++; z > 0; z--)
        System.out.print( c );

    }

Any help is appreciated

asked 43 secs ago

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.



Printing out a rhombic pattern in java with "for" loop

Aucun commentaire:

Enregistrer un commentaire