-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalci.java
More file actions
31 lines (30 loc) · 995 Bytes
/
calci.java
File metadata and controls
31 lines (30 loc) · 995 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
26
27
28
29
30
31
import java.util.*;
public class s {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number1:");
int n1 =input.nextInt();
System.out.print("Enter the number2:");
int n2 = input.nextInt();
input.nextLine();
input.nextLine();
System.out.print("Choose the operand:");
String operand = input.nextLine();
if(operand.equals("add")){
System.out.printf("The result is %d",n1+n2);
}else if(operand.equals("sub")){
System.out.printf("The result is %d",n1-n2);
}else if(operand.equals("Multiply")){
System.out.printf("The result is %d",n1*n2);
}else if(operand.equals("div")){
if(n2 == 0){
System.out.print("Cannot divide by zero");
}else{
System.out.printf("The result is %d",n1/n2);
}
}else{
System.out.printf("%s is not supported here.",operand);
}
input.close();
}
}