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); } } }

5 views0 comments

Recent Posts

See All

Calculate BMI in Java | AskTheCode

Write a Java program that reads values for weight in kilograms and height in centimeters and prints out the BMI... interpretation of it...

"Believe you can and you're halfway there"