0

What is the code for this?

If the user enters a number (ex. 5) the ouput ahould be like * \\ 4 spaces before the first "*" ** \\ 3 spaces *** \\ 2 spaces **** \\ 1space *****

30th Sep 2017, 7:32 AM
Jan Paul Echaveria
Jan Paul Echaveria - avatar
2 Answers
+ 12
int n = 5; int sp = 2*n - 2; // spaces for(int i = 1; i <= n; i++) { for(int j = 1; j <= sp; j++) { System.out.print(" "); } --sp; // sp-1 at each iteration for(int j = 1; j <= i; j++) { System.out.print("* "); } System.out.println(); } // Take the input (as n) as per your choice ^^
30th Sep 2017, 7:45 AM
Dev
Dev - avatar