'Error <identifier> expected for System.out.println(); ? How can I fix this?

Why do I get an error that says >error: identifier expected System.out.println(); . I need a new line after the last element in the array, that is why I added the println. How can I fix this?

     import java.util.Scanner;
public class LabProgram {
    public static void main(String args[]) {
    int n, left,right;
        Scanner s = new Scanner(System.in);
        n = s.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = s.nextInt();
        left=s.nextInt();
        right=s.nextInt();
        for(int i = 0; i < n; i++)
            //check if the current element is within the range
            if(a[i]>=left && a[i]<=right)
                System.out.print(a[i] + ",");
    }
    System.out.println();
}


Solution 1:[1]

SOP written outside the main method. It must be inside the main method. 

import java.util.Scanner;  
public class LabProgram {  
    public static void main(String args[]) {  
    int n, left,right;  
        Scanner s = new Scanner(System.in);  
        n = s.nextInt();  
        int a[] = new int[n];  
        for(int i = 0; i < n; i++)  
            a[i] = s.nextInt();  
        left=s.nextInt();  
        right=s.nextInt();  
        for(int i = 0; i < n; i++) { 
            //check if the current element is within the range  
            if(a[i]>=left && a[i]<=right)  
                System.out.print(a[i] + ",");  
    }  
    System.out.println();  
}  
} 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Java Team