-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.java
More file actions
25 lines (25 loc) · 860 Bytes
/
Copy pathoperators.java
File metadata and controls
25 lines (25 loc) · 860 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
import java.util.Scanner;
public class operators{
public int x;
public int y;
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.print("Enter the value of x : ");
int x = sc.nextInt();
System.out.print("Enter the operator to be used : ");
char op=sc.next().charAt(0);
System.out.print("Enter the value of y : ");
int y= sc.nextInt();
int result=0;
switch(op){
case '+':result=x+y;break;
case '-':result=x-y;break;
case '*':result=x*y;break;
case '/':result=x/y;break;
case '%':result=x%y;break;
default:System.out.println("Operator is invalid...");return;
}
System.out.println("the arithmetic operation of x & y : "+result);
sc.close();
}
}