-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.java
56 lines (46 loc) · 1.45 KB
/
main.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
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
import java.util.Scanner;
class Calculator {
public static int add(int a, int b) {
return a + b;
}
public static int subtract(int a, int b) {
return a - b;
}
public static int multiply(int a, int b) {
return a * b;
}
public static double divide(int a, int b) {
if (b == 0) {
throw new ArithmeticException("Cannot divide by zero");
}
return (double) a / b;
}
public static int power(int a, int b) {
int result = 1;
for(int i = 0; i<b; i++) {
result*=a;
}
return result;
}
public static int modulo(int a, int b) {
return a % b;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.printLn("Enter your numbers here: ");
int num1 = sc.nextInt();
int num2 = sc.nextInt();
int sum = add(num1, num2);
System.out.println("sum: " + sum);
int difference = subtract(num1, num2);
System.out.println("difference: " + difference);
int product = multiply(num1, num2);
System.out.println("product: " + product);
double quotient = divide(num1, num2);
System.out.println("Quotient: " + quotient);
double modulo = modulo(num1, num2);
System.out.println("Modulo: " + modulo);
int power = power(num1, num2);
System.out.println("Power: " + power);
}
}