Guest User

calculator

a guest
Jun 10th, 2015
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Calculator {
  3. public static void main(String[]args)
  4. {
  5. Numeric another=new Numeric();
  6. Scanner keyboard=new Scanner(System.in);
  7. String a , b, op;
  8.  
  9.  
  10. double c=0;
  11.  
  12. do
  13. {
  14. System.out.print("> ");
  15. a=keyboard.next();
  16. op=keyboard.next();
  17.  
  18. if(Numeric.isNumeric(a))
  19. {
  20. if(Numeric.isInteger(a))
  21. {
  22.  
  23. b=keyboard.next();
  24. int B=Integer.parseInt(b);
  25. int A=Integer.parseInt(a);
  26. if(op.equals("+"))
  27. {
  28. c=B+A;
  29.  
  30. }
  31. if(op.equals("-"))
  32. {
  33. c=B-A;
  34. }
  35. //etc
  36. }
  37. else if(Numeric.isDouble(a))
  38. {
  39.  
  40. }
  41. }
  42. else
  43. {
  44. if(a.equals("sin"))
  45. {
  46. double OP=Double.parseDouble(op);
  47. c=Math.sin(OP);
  48. }
  49. else if(a.equals("cos"))
  50. {
  51. double OP=Double.parseDouble(op);
  52. c=Math.cos(OP);
  53. }
  54. //etc
  55. }
  56.  
  57. System.out.println(c);
  58. }
  59. while(true);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment