JAVA
java
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
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Scanner;
/*
Enter first number, operations (+,-,*,/,% or ^) and second number with a space between them.
*/
public class Calculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
try {
double x = input.nextDouble();
String operation = input.next();
if (!operation.equals("+") && !operation.equals("-") && !operation.equals("*") && !operation.equals("/")
&& !operation.equals("%") && !operation.equals("^"))
throw new IOException("\nYou entered wrong operation, please try again.");
double y = input.nextDouble();
if (operation.equals("/") && y==0)
throw new ArithmeticException("\nCannot divide by zero.");
double result = 0;
switch (operation) {
case "+":
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run