-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
29 lines (28 loc) · 898 Bytes
/
Copy pathCalculator.java
File metadata and controls
29 lines (28 loc) · 898 Bytes
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
import java.util.Scanner;
class Calculator{
static int addition(int a,int b){
return a+b;
}
static int subtraction(int a, int b){
return a-b;
}
static int multiplication(int a,int b){
return a*b;
}
static int divide(int a,int b){
if(b==0){
throw new IllegalArgumentException("Divide by zero in not allowed");
}
return a/b;
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("please enter inter a and b ");
int a=sc.nextInt();
int b=sc.nextInt();
System.out.println("Additon of "+a+" and "+b+" is "+Calculator.addition(a,b));
System.out.println("subtraction of "+a+" and "+b+" is "+Calculator.subtraction(a,b));
System.out.println("multiplication of "+a+" and "+b+" is "+Calculator.multiplication(a,b));
System.out.println("divide of "+a+" by "+b+" is "+Calculator.divide(a,b));
}
}