Hackerrank – Problem Statement
A description of the problem can be found on Hackerrank.
Solution
I created solution in:
All solutions are also available on my GitHub.
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import java.util.*; class Solution { private static int B; private static int H; private static boolean flag = false; static { Scanner stdin = new Scanner(System.in); B = stdin.nextInt(); H = stdin.nextInt(); flag = B > 0 && H > 0; if(!flag) { System.out.println("java.lang.Exception: Breadth and height must be positive"); } stdin.close(); } public static void main(String [] args) { if(flag){ int area = B * H; System.out.print(area); } } } |