binary code, binary, binary system-475664.jpg
0 0
Read Time:34 Second

Static initialization blocks are executed when the class is loaded, and you can initialize static variables in those blocks.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
 public static boolean flag=false;
 public static int B=0;
 public static int H=0;
 
   static  {   
    Scanner scan= new Scanner(System.in);
    B= scan.nextInt();
    H=scan.nextInt();
  if(B>0 && H>0){
      flag=true;
  }else {
      flag=false;
      System.out.println("java.lang.Exception: Breadth and height must be positive");
  }
 }
 
public static void main(String[] args){
		if(flag){
			int area=B*H;
			System.out.print(area);
		}
		
	}//end of main

}//end of class

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

About Author

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *