Hi im writing a code that is supposed to display this

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

i have this so far

for (int i=0;i<6;i++){
     for (int j=0;j<i;j++){

which displays this

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

how do i get the reverse side

Edited 3 Years Ago by Reverend Jim: Fixed formatting

If you do increments on adding a star ,
you do the decrements on the reverse.
and you need to initialize your i to the number of stars.
inc
i = 0; i < 6; i++
dec
i = 6; i > 0; i--;

hope it helps;;

good luck

this is it what i was working on now with the decrement

package mid;
public class mid {
public static void main (String[]args){
        for (int i=1;i<6;i++){
         for (int j=0;j<i;j++){
              System.out.print("*");
           }

         System.out.println();
        }
            for (int i=6;i>0;i--){
             for (int j=7;j>i;j--){
             System.out.print("*");
             }
              System.out.println();
            }


}
}

and i got this

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

Edited 3 Years Ago by Reverend Jim: Fixed formatting

you really wrote your program very well. your first for loop(increment) is great and you make it work the way you wanted,

you might want to write the outer for loop like this: for (int i=1;i<7;i++)

on the second loop (decrement) you have to increment the outer for loop needs to be revised. and the inner for loop seems to work however it will stop after it prints the 2 stars. if you want to print all the way to the end you will have to write it as

for (int j=6;j>=i;j--)

try changing your for loops and let me know what happens

package mid;
public class mid {
    public static void main (String[]args){
            for (int i=1;i<6;i++){
             for (int j=0;j<i;j++){
                  System.out.print("*");
               }

             System.out.println();
            }
                for (int i=0;i<6;i++){
                 for (int j=6;j>i;j--){
                 System.out.print("*");
                 }
                  System.out.println();
                }


    }
}

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

victory thankyou for all your help

Edited 3 Years Ago by Reverend Jim: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.