my code:
Scanner s = new Scanner(System.in);
int n = s.nextInt();
// Ques 20:
// n = 7
// - - - *
// - - * - *
// - * - - - *
// * - - - - - *
// - * - - - *
// - - * - *
// - - - *
// row
int row = 1;
// work
int nst = 1;
int nsp = n / 2;
while (row <= n) {
// work space
int csp = 1;
while (csp <= nsp) {
System.out.print("- ");
csp++;
}
// work stars
int cst = 1;
while (cst <= nst) {
System.out.print("* ");
cst++;
}
// preparation
if (row <= n / 2) {
nsp--;
nst = nst + 2;
} else {
nsp++;
nst = nst - 2;
}
System.out.println();
row++;
}