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 *****
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 ^^