0
0
Read Time:34 Second
Static initialization blocks are executed when the class is loaded, and you can initialize static variables in those blocks.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static boolean flag=false;
public static int B=0;
public static int H=0;
static {
Scanner scan= new Scanner(System.in);
B= scan.nextInt();
H=scan.nextInt();
if(B>0 && H>0){
flag=true;
}else {
flag=false;
System.out.println("java.lang.Exception: Breadth and height must be positive");
}
}
public static void main(String[] args){
if(flag){
int area=B*H;
System.out.print(area);
}
}//end of main
}//end of class