Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CheapCalculator {
- private static double a,b;
- private static String operator;
- public static void main(String[] args) {
- Scanner kb= new Scanner(System.in);
- System.out.print("Enter a binary arithmetic expression, with spaces between operands and operator.\n\n");
- a= kb.nextDouble();
- operator = kb.nextLine();
- b = kb.nextDouble();
- //ask user to input arithmetic
- if (operator.equals("*"))
- {
- double multiply= a*b;
- System.out.println(multiply);
- }
- else if (operator.equals("/"))
- {
- double divide= a/b;
- System.out.println(divide);
- }
- else if (operator.equals("+"))
- {
- double add=a+b;
- System.out.println(add);
- }
- else if (operator.equals("-"))
- {
- double subtract= a-b;
- System.out.println(subtract);
- }
- else if (operator.equals("%"))
- {
- double remainder=a%b;
- System.out.println(remainder);
- }
- else
- {
- System.out.printf("Sorry dont know operator %s", operator);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement