Mam i have problem in in my pattern printing question no 19 of practice sheet . I am getting wrong pattern as output.
Regarding pattern in practice sheet
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int nsp=-1;
int nst=n/2;
int cst;
for(int i=1;i<=n;i++) {
int x=nst;
if(i==1 || i==n) {
x--;
}
for(cst=1;cst<=x+1;cst++) {
System.out.print("*");
}
for(int csp=1;csp<=nsp;csp++) {
System.out.print(" ");
}
for(cst=1;cst<=nst+1;cst++) {
System.out.print("*");
}
System.out.println();
if(i<=n/2) {
nst--;
nsp+=2;
}
else {
nst++;
nsp-=2;
}
}
}
@ravimaurya096_47edb35d740b0342 Bro this is the correct code for your problem. I have corrected yours you have to start nsp from -1 and increase it by 2 and after n/2 iterations we will decrement it by 2. And there are some other changes also check them.
And please share your code in text form from next time onwards.