+ 1

How can I create this

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

13th Apr 2017, 12:39 AM
Muhammad sani
Muhammad sani  - avatar
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); } }
13th Apr 2017, 4:38 AM
Rrestoring faith
Rrestoring faith - avatar
+ 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
13th Apr 2017, 12:51 AM
Thanh Le
Thanh Le - avatar
+ 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(); } } }
13th Apr 2017, 4:08 AM
Babak
Babak - avatar
+ 1
int i, j; for(i=5;i>=1;i--) { for(j=1;j<=i;j++) { System.out.print("*"); } System.out.println(); }
13th Apr 2017, 3:55 AM
Mahmoud Zardi
Mahmoud Zardi - avatar