Java Static Initializer Block | HackerRank

Random Post | #AskTheCode

import*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static Scanner input = new Scanner(; static int B = input.nextInt(); static int H = input.nextInt(); static Boolean flag = B > 0 && H > 0; static{ if(!flag){ 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); } } }

6 views0 comments

Recent Posts

See All

Golf CodeChef Solution in Java - AskTheCode

CodeChef May Long Challenge Solution | Golf (LKDNGOLF) solution | AskTheCode Golf (LKDNGOLF) solution Problem: It's a lockdown. You’re bored in your house and are playing golf in the hallway. The hall

Solubility - CodeChef Solution in Java and C++| AskTheCode

CodeChef May Long Challenge Solution | Solubility (SOLBLTY) solution | AskTheCode Solubility (SOLBLTY) solution Problem: Suppose for a unit rise in temperature, the solubility of sugar in water increa

Valid Paths CodeChef Solution in C++ | AskTheCode

CodeChef May Long Challenge Solution | Valid Paths (VPATH) solution | AskTheCode Valid Paths (VPATH) CodeChef solution Problem: You are given a tree with N nodes numbered from 1 to N. A set S of nodes