-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
57 lines (43 loc) · 1.01 KB
/
Calculator.java
File metadata and controls
57 lines (43 loc) · 1.01 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
//this is s simple Java calculator for doing the basic arithametic operations
public class Calculator{
int a;
int b;
public Calculator(){
a = a;
b = b;
}
public int add(int a,int b){
return a + b;
}
public int subtract(int a,int b){
return a - b;
}
public int multiply(int a,int b){
return a * b;
}
public double divide(double a,double b){
if (b != 0){
return (a / b);
}
else{
System.out.println("Error! You cannot divide a number by zero!");
return 0;
}
}
public int modulo(int a,int b){
if (b == 0){
System.out.println("Error! Divison by Zero is not allowed!");
return 0;
}
else{
return (a % b);
}
}
public static void main(String[] args){
Calculator myCalculator = new Calculator();
System.out.println(myCalculator.add(5,7));
System.out.println(myCalculator.subtract(45,11));
System.out.println(myCalculator.multiply(14640,45454));
System.out.println(myCalculator.divide(45,0));
}
}