Hackerrank - Java Solution - Java Static Initializer Block Solution
Problem Link - Java Static Initializer Block
Level - Introduction Challenges
Java Static Initializer Full Code
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
private static int B;
private static int H;
private static boolean flag;
static {
Scanner scan = new Scanner(System.in);
B = scan.nextInt();
H = scan.nextInt();
scan.close();
if (B <= 0 || H <= 0) {
System.out.println("java.lang.Exception: Breadth and height must be positive");
flag = false;
} else {
flag = true;
}
}
public static void main(String[] args) {
if (flag) {
int area = B * H;
System.out.print(area);
}
} // end of main
} // end of class
Java Static Initializer Only Code For Submit
private static int B;
private static int H;
private static boolean flag;
static {
Scanner scan = new Scanner(System.in);
B = scan.nextInt();
H = scan.nextInt();
scan.close();
if (B <= 0 || H <= 0) {
System.out.println("java.lang.Exception: Breadth and height must be positive");
flag = false;
} else {
flag = true;
}
}
Tags: HackerRank Online Judge Solution, HackerRank OJ Solution list, HackerRank Problems Solution, HackerRank solver, HackerRank all problem solution list, HackerRank solution in java, Hackerrank Java Solution, Hackerrank Online Judge Solution, Hackerrank - Java Solutions, Hackerrank - Java Solution - Java Static Initializer Block Solution
No comments:
Post a Comment