Java Static Initializer Block

  • + 0 comments

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = 0;
        boolean flag = true;
        if(a>=0 && b>=0){
            if(a>0 || a<0 && b>0 || b<0){
            c=a*b;
            if(c!=0 && c>=0){
                flag = false;
            }
            System.out.println(c);
        }
        }
    
        if(flag){
            try{
                throw(new IOException("java.lang.Exception: Breadth and height must be positive"));
            }catch(Exception e){
                System.out.println(e.getMessage());
            }
        }
        sc.close();
    }