Java Static Initializer Block

  • + 0 comments
    static boolean flag;
    static int B,H;
    

    static {

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

    }