-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEpamtask2.java
More file actions
92 lines (91 loc) · 1.85 KB
/
Epamtask2.java
File metadata and controls
92 lines (91 loc) · 1.85 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package myfirst;
import java.util.*;
public class Epamtask2 {
static int a;
static int b;
static Scanner scan=new Scanner(System.in);
public static void read()
{
System.out.println("Enter first operand");
a=scan.nextInt();
System.out.println("Enter second operand");
b=scan.nextInt();
}
public static void show(int value)
{
System.out.println(value);
}
public static int add(int val1,int val2)
{
int val3=Integer.MIN_VALUE;
val3=val1+val2;
return val3;
}
public static int subtract(int val1,int val2)
{
int val3=Integer.MIN_VALUE;
val3=val1-val2;
return val3;
}
public static int multi(int val1,int val2)
{
int val3=Integer.MIN_VALUE;
val3=val1*val2;
return val3;
}
public static int divide(int val1,int val2)
{
int val3=Integer.MIN_VALUE;
if(val2==0)
return val3;
else
val3=val1/val2;
return val3;
}
public static void check(char ch)
{
int x=0;
int flag=1;
switch(ch)
{
case '+':
System.out.println("It is Addition Operation");
x=add(a,b);
break;
case '-':
System.out.println("It is Subtraction Operation");
x=subtract(a,b);
break;
case '*':
System.out.println("It is Multiplication Operation");
x=multi(a,b);
break;
case '/':
System.out.println("It is Division Operation");
if(b!=0)
{
x=divide(a,b);
}
else
{
System.out.println("Division is not possible with divisor equal to Zero ");
flag=0;
}
break;
default:
flag=0;
System.out.println("It is not a Arithmetic operator");
}
if(flag==1)
{
show(x);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
read();
System.out.println("Enter the Arithmetic operator");
char operator=(scan.next()).charAt(0);
check(operator);
}
}