You just need to build the squares until you exceed the value N. Try:
    public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);
        int n = entrada.nextInt();
        for (int i = 1; i * i <= n; i++) {
            System.out.println(i * i);
        }
    }
3
solved Print all the squares from natural numbers [closed]