-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathjava-static-initializer-block.java
More file actions
45 lines (36 loc) · 1.04 KB
/
java-static-initializer-block.java
File metadata and controls
45 lines (36 loc) · 1.04 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Java > Introduction > Java Static Initializer Block
// Initialize some variables using Static initialization blocks!
//
// https://www.hackerrank.com/challenges/java-static-initializer-block/problem
// challenge id: 13800
//
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
// (skeliton_head) ----------------------------------------------------------------------
private static boolean flag;
private static int B, H;
static {
Scanner scanner = new Scanner(System.in);
B = scanner.nextInt();
H = scanner.nextInt();
scanner.close();
flag = (B > 0 && H > 0);
try {
if (! flag)
throw new Exception("Breadth and height must be positive");
} catch (Exception e) {
System.out.println(e);
}
}
// (skeliton_tail) ----------------------------------------------------------------------
public static void main(String[] args){
if(flag){
int area=B*H;
System.out.print(area);
}
}//end of main
}//end of class