Java Static Initializer Block

  • + 0 comments

    private String message; Solution(String message) { this.message=message; } @Override public String getMessage() { return message; }

    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int b=sc.nextInt();
       sc.nextLine();
       int h=sc.nextInt();
       sc.close();
       if(b>0 && h>0)
       {
        System.out.println(b*h);
       }
       else
       {
        try{
            throw new Solution("java.lang.Exception: Breadth and height must be positive");
        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
       }
    }