Java Static Initializer Block

  • + 7 comments

    static boolean flag=true;

    static int B,H;

    static {

    Scanner scan = new Scanner(System.in);
    
    B = scan.nextInt();
    
    H = scan.nextInt();
    
    try{   
    
    if(B<=0 || H<=0){
    
    flag = false;
    
    throw new Exception("Breadth and height must be positive");
    
    } 
    
    }catch(Exception e){
    
    System.out.println(e);
    
    }
    

    }