-
Notifications
You must be signed in to change notification settings - Fork 1
/
465 - Overflow.cpp
35 lines (32 loc) · 1.01 KB
/
465 - Overflow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.math.BigDecimal;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
String n1=in.next();
BigDecimal num1=new BigDecimal(n1);
String oprtn= in.next();
String n2=in.next();
BigDecimal num2=new BigDecimal(n2);
BigDecimal sum= new BigDecimal("0");
if(oprtn.equals("+")){
sum=num1.add(num2);
}
else
sum=num1.multiply(num2);
BigDecimal maximum=new BigDecimal("2147483647");
int check=num1.compareTo(maximum);
System.out.println(n1+" "+oprtn+" "+n2);
if(check==1)
System.out.println("first number too big");
check=num2.compareTo(maximum);
if(check==1)
System.out.println("second number too big");
check=sum.compareTo(maximum);
if(check==1)
System.out.println("result too big");
}
}
}