Pattern-can my code be corrected
@Utkarshsingh5298291
Bro please find attached your corrected code below:-
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int nst=n/2+1;
int nst2=n/2+1; //change 1
int nsp=-1; //change 2
//row
int row=1;
while(row<=n)
{
//work star
if(row==1 || row==n){ //change 3
int cst=1;
while(cst<=n){
System.out.print("* ");
cst++;
}
}
else{
int cst=1;
while(cst<=nst)
{
System.out.print("* ");
cst++;
}
//work spaces
int csp=1;
while(csp<=nsp)
{
System.out.print(" ");
csp++;
}
// // work star
cst=1;
while(cst<=nst2)
{
System.out.print("* ");
cst++;
}
}
//prepration step
System.out.println();
if(row<=n/2)
{
nsp=nsp+2;
nst--;
nst2--;
}
else {
nsp=nsp-2;
nst++;
nst2++;
}
row++;
}
}
}
And if you have any doubts, lemme know else resolve the doubt and rate.
I have been solving questions from last 3 hours ,now brain is not working ! Please can you tell m what changes did you make although i can see few changes like—
if(row==1 || row==n)
Thanks in advance…!
@Utkarshsingh5298291 You can check the change comments in the code above. Apart from that i have just added tabs as asked in question. Rest dry run your code you will get the knack.
Also resolve the doubt if solved.