Java basic challenges

i am anable to solve invertedHourGlass question of challange .this is my code please point my error

import java.util.;
public class Main {
public static void main(String args[]) {
Scanner scn=new Scanner(System.in);
int n=0;
if(scn.hasNext()){
n=scn.nextInt();
}
int nst=1;
int nsp=2
n-1;
int nr=2*n+1;
//row
int row=1;
while(row<=nr){
//value
for(int cst=1;cst<=nst;cst++){
System.out.print(n);
n–;
}
//space
for(int csp=1;csp<=nsp;csp++){
System.out.print(" ");
}
//value
for(int cst=1;cst<=nst;cst++){
int cnt=n-row+cst;
System.out.print(cnt);
}
}
System.out.println();
if(row<=6){
nst=nst+1;
nsp=nsp-2;
}
else{
nst=nst-1;
nsp=nsp+2;
}
row++;
}
}

Any reply? I am stuck in this problem.

Why have you used

if(row<=6)

This limits your code to one test case. Dont hard code it

import java.util.; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=0; if(sc.hasNext()){ n=sc.nextInt(); } int i,j,k,space; for(i=0;i<=n;i++){ for(j=n;j>=n-i;j–){ System.out.print(j); } int c=n-i; for(space=1;space<=2c-1;space++){ System.out.print(" ā€œ); } for(k=n-i;k<=n;k++){ if(k==0) continue; System.out.print(k); } System.out.println(); } for(i=0;i<n;i++){ for(j=n;j>i;j–){ System.out.print(j); } for(space=1;space<=2*i+1;space++){ System.out.print(ā€ "); } for(k=i+1;k<=n;k++){ System.out.print(k); } System.out.println(); } } }

it shows wrong answer.no test case is passed

please share your code after saving it on ide.codingblocks.com