-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigIntRun.java
More file actions
60 lines (56 loc) · 2.07 KB
/
BigIntRun.java
File metadata and controls
60 lines (56 loc) · 2.07 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;
public class BigIntRun {
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
BigInt num1 = null;
BigInt num2 = null;
BigInt temp;
int comp;
final int QUANTITY = 2;
for(int i=0; i<QUANTITY ; i++)
{
temp = null;
System.out.println("Please enter number #" +(i+1) +" :");
while (temp == null)
{
String num = scan.nextLine();
try{
temp = new BigInt(num);
} catch (IllegalArgumentException e)
{
System.out.println("The Input is illegal, must enter an integer number\nPlease try again");
}
}
if(i==0)
num1 = new BigInt(temp);
else
num2 = new BigInt(temp);
}
System.out.println("The first number is: " + num1);
System.out.println("The second number is: " + num2);
System.out.println(num1 + " + " + num2 + " = " + num1.plus(num2));
System.out.println(num1 + " - " + num2 + " = " + num1.minus(num2));
System.out.println(num1 + " * " + num2 + " = " + num1.multiply(num2));
try {
System.out.println(num1 + " / " + num2 + " = " + num1.divide(num2));
} catch (ArithmeticException e) {
System.out.println("It's illegal to divide an number with Zero");
}
System.out.println("Does " + num1 + " equals " + num2 + " ? " + num1.equals(num2));
comp = num1.compareTo(num2);
System.out.println("If we compare the numbers we will get: " +comp);
if(comp<0)
{
System.out.println("Which means that the first number is *smaller* than the second");
}
else if (comp==0)
{
System.out.println("Which means that the first *equals* the second");
}
else if(comp>0)
{
System.out.println("Which means that the first number is *greater* than the second");
}
}
}