We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = 0;
boolean flag = true;
if(a>=0 && b>=0){
if(a>0 || a<0 && b>0 || b<0){
c=a*b;
if(c!=0 && c>=0){
flag = false;
}
System.out.println(c);
}
}
if(flag){
try{
throw(new IOException("java.lang.Exception: Breadth and height must be positive"));
}catch(Exception e){
System.out.println(e.getMessage());
}
}
sc.close();
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Static Initializer Block
You are viewing a single comment's thread. Return to all comments →
public static void main(String[] args) {