Java Static Initializer Block

  • + 0 comments

    static{ Scanner scan = new Scanner(System.in); int b = scan.nextInt(); int h = scan.nextInt(); try{ if(b <= 0 || h <= 0) throw new Exception("Breadth and height must be positive"); System.out.println(b*h);
    }catch(Exception e){ System.out.println(e); } }