-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathfunction.java
More file actions
72 lines (68 loc) · 1.06 KB
/
function.java
File metadata and controls
72 lines (68 loc) · 1.06 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.io.*;
import java.util.*;
public class function
{
public static void main(String args[])
{
DataInputStream dis = new DataInputStream(System.in);
try
{
System.out.println("Enter value of a:");
int a = Integer.parseInt(dis.readLine());
System.out.println("Enter value of b:");
int b = Integer.parseInt(dis.readLine());
System.out.println("Enter value of c:");
int c = Integer.parseInt(dis.readLine());
Calculator cal = new Calculator();
int d = cal.calculation(a,b,c);
System.out.println(d);
}
catch(Exception e)
{}
}
}
class Calculator
{
int calculation(int x,int y,int z)
{
int w = 0;
if(x>=0 && y>=0)
{
if(z==1)
{
w =(x+y);
}
if(z==2)
{
if(x>y)
{
w = (x-y);
}
else
{
w= (y-x);
}
}
if(z==3)
{
w = (x*y);
}
if(z==4)
{
if(y != 0)
{
w = (x/y);
}
}
if(z>4)
{
System.out.println("The number must be between 1 to 4");
}
}
else
{
System.out.println("a and b must be positive");
}
return w;
}
}