Java Static Initializer Block

  • + 0 comments
    public class Solution {
        
    public static int B;
    public static int H;
    public static boolean flag = printArea();
    
    public static boolean printArea() {
        Scanner sc = new Scanner(System.in);
        // System.out.println("Enter two numbers between -100 and 100");
        B = sc.nextInt();
        H = sc.nextInt();
        sc.close();
            Solution.flag = (B<=0 || H<=0)? false: true;
            if(!flag){
                System.out.println( "java.lang.Exception: Breadth and height must be positive");
            }
            return Solution.flag;
    }
    
    public static void main(String[] args){
    		if(flag){
    			int area=B*H;
    			System.out.print(area);
    		}
    
    }//end of main``
    }//end of class