+ 1
How can I create this
***** **** *** ** *
4 Answers
+ 6
How about some recursion đ.
Call this function with the number of lines you want to make. So: stars(5,5); for what you wanted.
private static void stars(int num,int next){
if(num==0){
System.out.println();
stars(next-1, next-1);
}
else if(num>0){
System.out.print("*");
stars(num-1, next);
}
}
+ 3
I implemented with a double for-loop in JS:
for (let i = 5; i > 0; i--) {
let points = "";
for (let j = i; j > 0; j--) {
points+= "* ";
}
console.log(points);
}
You can test it here:
https://jsbin.com/ralivewixi/edit?js,console
+ 3
/* V Arc */
public class Program
{
public static void main(String[] args) {
int i, j, k;
int n = 5, l = 0;
for (i = 1; i <= n; ++i)
{
for (j = n; j >= i; --j)
System.out.print("*");
// extended part started from here
++j;
for (k = n; k > n - j - l; --k)
System.out.print(" ");
++l;
for (int z = n; z >= l; --z)
System.out.print("*");
// extended part ended
System.out.println();
}
}
}
+ 1
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}