I am not getting the right answer from this code

import java.util.Scanner;

public class Practice{

public static void main(String[] args) {
	// TODO Auto-generated method stub
  Scanner scn= new Scanner(System.in);
  int n = 10001;
  while (n >1000) {

      System.out.println("Enter an integer " + 
                         "with in range 0-1000");
      n = scn.nextInt();
  }
  int nst = 1;
  for(int row=1; row<=n ; row++)
  {
	  for(int star=1; star<=nst; star++)
	  {   if(star==1 || star ==nst)
		  System.out.print(row);
	  else
		  System.out.print("0");
	  }
	   System.out.print("\n");
	  nst++;    	  
  }
}

}

You don’t need to print “enter the number …”

import java.util.Scanner;

public class icpc1{

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner scn= new Scanner(System.in);
    int n = 10001;
    while (n >1000) {

        System.out.println("Enter an integer " +
                "with in range 0-1000");
        n = scn.nextInt();
    }
    int nst = 1;
    for(int row=0; row<n ; row++)
    {
        for(int star=1; star<=nst; star++)
        {   if(star==1 || star ==nst)
            {
                if(row == 0)
                    System.out.print(1);
                else
                    System.out.print(row);
            }
        else
            System.out.print("0");
        }
        System.out.print("\n");
        nst++;
    }
}

}

This is the correct code with a little modifications to your existing code.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.