-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathCalculator
66 lines (61 loc) · 1.07 KB
/
Calculator
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
61
62
63
64
65
66
import java.util.*;
class Calculator
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
float a, b; //a<=50000, b<=50000
int choice;
System.out.println("Enter two numbers:");
a = sc.nextFloat();
b = sc.nextFloat();
if(a<=50000 && b<=50000)
{
System.out.println("Enter you choice");
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
choice = sc.nextInt();
switch(choice)
{
case 1:
{
System.out.print(add(a, b));
break;
}
case 2:
{
System.out.print(sub(a, b));
break;
}
case 3:
{
System.out.print(mul(a, b));
break;
}
case 4:
{
System.out.print(div(a, b));
break;
}
}
}
System.out.println("\nInputs are not in range of 50000");
}
static float add(float x, float y)
{
return x+y;
}
static float sub(float x, float y)
{
return x-y;
}
static float mul(float x, float y)
{
return x*y;
}
static float div(float x, float y)
{
return x/y;
}
}