import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter operation (+ for addition, - for subtraction, * for multiplication): ");
char operation = scanner.next().charAt(0);
System.out.print("Enter first number: ");
String num1 = scanner.next();
System.out.print("Enter second number: ");
String num2 = scanner.next();
double x, y;
if (num1.contains(".") || num2.contains(".")) {
x = Double.parseDouble(num1);
y = Double.parseDouble(num2);
} else {
x = Integer.parseInt(num1);
y = Integer.parseInt(num2);
}
double result;
switch (operation) {
case '+':
result = add(x, y);
break;
case '-':
result = subtract(x, y);
break;
case '*':
result = multiply(x, y);
break;
default:
System.out.println("Invalid operation");
return;
}
System.out.println("The result is: " + result);
}
public static double add(double x, double y) {
return x + y;
}
public static double subtract(double x, double y) {
return x - y;
}
public static double multiply(double x, double y) {
return x * y;
}
}