-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathSimple Calculator in JAVA
33 lines (32 loc) · 1.13 KB
/
Simple Calculator in 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
import java.util.*;
public class SimpleCalculator{
public static double add(double x, double y){
return x+y;
}
public static double subtract(double x, double y){
return x-y;
}
public static double mul(double x, double y){
return x*y;
}
public static double div(double x, double y){
return x/y;
}
public static double mod(double x, double y){
return x%y;
}
public static void main(String[] args) {
System.out.println("Simple Calculator:");
Scanner ob = new Scanner(System.in);
System.out.println("Enter first number: ");
double a = ob.nextDouble();
System.out.println("Enter second number: ");
double b = ob.nextDouble();
System.out.println("Addition of "+a+" and "+b+" is "+ add(a,b));
System.out.println("Subtraction of "+a+" and "+b+" is "+ subtract(a,b));
System.out.println("Multiplication of "+a+" and "+b+" is "+ mul(a,b));
System.out.println("Division of "+a+" and "+b+" is "+ div(a,b));
System.out.println("Mod of "+a+" and " +b+ " is "+mod(a,b));
ob.close();
}
}