-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSolution.java
More file actions
39 lines (30 loc) · 894 Bytes
/
Copy pathSolution.java
File metadata and controls
39 lines (30 loc) · 894 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
31
32
33
34
35
36
37
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
private static boolean flag;
private static int B;
private static int H;
static {
// Note: this is a poor example of using static initialization blocks.
// This exercise was very poorly written.
Scanner sc = new Scanner(System.in);
B = Integer.parseInt(sc.nextLine());
H = Integer.parseInt(sc.nextLine());
if(B <= 0 || H <= 0) {
flag = false;
// Note: this is a bad practice. This exercise is poorly written. Instead this should throw an error.
System.out.println("java.lang.Exception: Breadth and height must be positive");
} else {
flag = true;
}
}
public static void main(String[] args){
if(flag){
int area=B*H;
System.out.print(area);
}
}//end of main
}//end of class