#making a specific pattern
1 messages · Page 1 of 1 (latest)
can you paste the code here with
;compile java
public class Main
{
public static void main(String args[]) {
}
}
Compilation successful
No output.
fd26#6261 | 110ms | java | jdk 18.0.0 | godbolt.org
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
*
***
*****
*******
*********
mb for the trouble tech issues lol
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();
}
}
}
Program Output
*
***
*****
*******
*********
fd26#6261 | 76ms | java | jdk 18.0.0 | godbolt.org
;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();
}
}
}
Program Output
*
***
*****
*******
*********
fd26#6261 | 125ms | java | jdk 18.0.0 | godbolt.org
;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();
}
}
}
Program Output
*
***
*****
*******
*********
fd26#6261 | 75ms | java | jdk 18.0.0 | godbolt.org
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();
}
}
}
Program Output
.
*
***
*****
*******
*********
fd26#6261 | 101ms | java | jdk 18.0.0 | godbolt.org
i think this is the easiest to understand wait so basically all i do is change the middle inside loo p right
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 ❤️