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

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

it just loops it never reaches 0 it infinite loops

can you post your revise program? Id like to run it in my compiler

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.