Advertisement
JDMshifter

programcalculatorsimple

Feb 26th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class CheapCalculator {
  5. private static double a,b;
  6. private static String operator;
  7.  
  8. public static void main(String[] args) {
  9.  
  10. Scanner kb= new Scanner(System.in);
  11.  
  12. System.out.print("Enter a binary arithmetic expression, with spaces between operands and operator.\n\n");
  13. a= kb.nextDouble();
  14. operator = kb.nextLine();
  15. b = kb.nextDouble();
  16. //ask user to input arithmetic
  17. if (operator.equals("*"))
  18. {
  19. double multiply= a*b;
  20. System.out.println(multiply);
  21. }
  22. else if (operator.equals("/"))
  23. {
  24. double divide= a/b;
  25. System.out.println(divide);
  26. }
  27. else if (operator.equals("+"))
  28. {
  29. double add=a+b;
  30. System.out.println(add);
  31. }
  32. else if (operator.equals("-"))
  33. {
  34. double subtract= a-b;
  35. System.out.println(subtract);
  36. }
  37. else if (operator.equals("%"))
  38. {
  39. double remainder=a%b;
  40. System.out.println(remainder);
  41. }
  42. else
  43. {
  44. System.out.printf("Sorry dont know operator %s", operator);
  45. }
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement