I made some changes to your code, it works fine.
However, the approach using Stack is better because allows you not only see if the amout of parenthesis is equal, but to see if the expression is correct. For example, if you have something like that: (x+y))+(x-(y+x) then your program can't tell that this is an incorrect expression because the amount of opening and closing parenthesis is equal.
import java.util.*;
public class Stackpr {
public static void main (String[] args)
{
String line; // the string of characters to be checked
Scanner scan = new Scanner(System.in);
System.out.println ("\nParenthesis Matching");
System.out.print ("Enter a parenthesized expression: ");
line = scan.nextLine();
int l = 0;
int r = 0;
for (int i = 0; i < line.length(); i++){
if (line.charAt(i) == '(')
l++;
else if (line.charAt(i) == ')')
r++;
}
if (l > r)
System.out.println("There are " + (l-r) + " more left parentheses than right");
else if (l < r)
System.out.println("There are " + (r - l)+ " more right parentheses then left");
else
System.out.println("The amount of left and right parentheses are even.");
}
}