В чем разница между инициализацией в статическом
блоке:
public class staticTest {
static String s;
static int n;
static double d;
static {
s = "I'm static";
n = 500;
d = 4000.0001;
}
...
И индивидуальной статической инициализацией:
public class staticTest {
static String s = "I'm static";
static int n = 500;
static double d = 4000.0001;
....
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static Scanner sc=new Scanner(System.in);
public static int B=sc.nextInt();
public static int H=sc.nextInt();
public static boolean flag=false;
static
{
if(B>0 && H>0)
{
flag=true;
}
else
{
System.out.print("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