Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Calculator {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Enter the first number: ");
- double num1 = scanner.nextDouble();
- System.out.println("Enter the second number: ");
- double num2 = scanner.nextDouble();
- System.out.println("Enter the operation (+, -, *, /): ");
- char operation = scanner.next().charAt(0);
- double result;
- switch (operation) {
- case '+':
- result = num1 + num2;
- System.out.println("Result: " + result);
- break;
- case '-':
- result = num1 - num2;
- System.out.println("Result: " + result);
- break;
- case '*':
- result = num1 * num2;
- System.out.println("Result: " + result);
- break;
- case '/':
- result = num1 / num2;
- System.out.println("Result: " + result);
- break;
- default:
- System.out.println("Invalid operation.");
- }
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement