-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatic_block.java
More file actions
30 lines (28 loc) · 815 Bytes
/
Static_block.java
File metadata and controls
30 lines (28 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static Scanner sc = new Scanner(System.in); // System.in imp coz else error: no suitable constructor found for Scanner()
static int B= sc.nextInt();
static int H= sc.nextInt();
static boolean flag = true; // not 1
static{
try{
if(B<=0 || H<=0){
flag=false;
throw new Exception("Breadth and height must be positive"); //IMP
}
}
catch(Exception e) {
System.out.println(e);
}
}
public static void main(String[] args){
if(flag){ // Flag imp coz it will still proceed to main coz of exception not error
int area=B*H;
System.out.print(area);
}
}
}