Reputation: 21
So I know this error is when there is a bracket missing, but I have checked and this code works in IntelliJ, so any ideas what else might be causing it or am I just so blind :(
class Solution {
static int B;
static int H;
static boolean flag = true;
static Scanner scanner = new Scanner(System.in);
static {
int B = scanner.nextInt();
int H = scanner.nextInt();
scanner.close();
try {
if (B <= 0 || H <= 0) {
flaf = false;
throw new Exception ("java.lang.Exception: Breadth and height must be positive");
}
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}
}
public static void main(String[] args){
if(flag){
int area=B*H;
System.out.print(area);
}
}//end of main
}//end of class
Upvotes: 1
Views: 353
Reputation: 143
The brackets look fine.
One error I see is a typo.
if (B <= 0 || H <= 0) { flaf = false;
instead of flag, you typed "flaf".
I copied an ran your code in eclipse it runs fine.
Upvotes: 1