#making a specific pattern

1 messages · Page 1 of 1 (latest)

lofty sleet
#

making a specific pattern

tropic linden
#

can you paste the code here with

#

;compile java

public class Main
{
   public static void main(String args[]) {
   } 
}
dawn tokenBOT
#
Compilation successful

No output.

tropic linden
#

what is the pattern supposed to be?!?

#

visually

lofty sleet
#

Okay

#
public class Main
{
   public static void main(String args[]) {

    for (int i = 0; i <= 5; i++)  // row 
    {
      for (int j = 8; j <= i+1 ; j++) //col
      {
        System.out.print("* ");
      }
    
      
      System.out.println();
    }
  }

   } 
}
#

goal is to print

*

***

*****

*******

*********
lofty sleet
tropic linden
#

so 1 3 5 7 9

#

;compile java

public class Main
{
    public static void main(String args[])
    {
        for (int i = 0; i < 5; ++i)  // row
        {
            // 0, 2, 4, 6, 8
            // 1, 3, 5, 7, 9
            final int n = (i * 2) + 1;
            for (int j = 0; j < n; ++j) // col
            {
                System.out.print("*");
            }

            System.out.println();
            System.out.println();
        }
    }
}
dawn tokenBOT
#
Program Output
*

***

*****

*******

*********
tropic linden
#

;compile java

public class Main
{
    public static void main(String args[])
    {
        for (int i = 0; i < 5; ++i)  // row
        {
            // 0, 2, 4, 6, 8
            // 1, 3, 5, 7, 9
            for (int j = 0; j <= (i * 2); ++j) // col
            {
                System.out.print("*");
            }

            System.out.println();
            System.out.println();
        }
    }
}
dawn tokenBOT
#
Program Output
*

***

*****

*******

*********
tropic linden
#

;compile java

public class Main
{
    public static void main(String args[])
    {
        for (int i = 0; i < 5; ++i)  // row
        {
            for (int j = 0; j < i; ++j) // col
            {
                System.out.print("**");
            }

            System.out.println("*");
            System.out.println();
        }
    }
}
dawn tokenBOT
#
Program Output
*

***

*****

*******

*********
tropic linden
#

here's 3 versions of the code 🙂

#

if you don't want "double line" remove the last System.out.println()

#

if you want a xmas tree, you need to print blanks first

#

;compile java

public class Main
{
    public static void main(String args[])
    {
        System.out.println("."); //!< Only needed for compile java output
        for (int i = 0; i < 5; ++i)  //!< Row
        {
            if (true) //!< XMAS tree layout or not
            for (int k = 0; k < (4 - i); ++k) //!< Blank column
            {
                System.out.print(" ");
            }

            for (int j = 0; j < i; ++j) //!< Star column
            {
                System.out.print("**");
            }

            System.out.println("*");
            // System.out.println();
        }
    }
}
dawn tokenBOT
#
Program Output
.
    *
   ***
  *****
 *******
*********
lofty sleet
#

and i think my mistake is i forgot to put when it increments to double star not single star also if u can can u explain like the j < i thats kinda confusing i think thats why i got stuck

#

thanks btw! appreciate it ❤️

tropic linden
#

double star is to avoid (I*2)

#

and <= to avoid +1

#

or put print("*") outside the loop for the +1