HarryJW

JavaCalculator (Problem)

Jan 4th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package javaCalculator;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Calculator {
  6.  
  7. public static void main (String [] args) {
  8.  
  9.  
  10. System.out.println("Please enter your first number");
  11. Scanner Scanner1 = new Scanner (System.in);
  12. int firstInteger = Scanner1.nextInt();
  13.  
  14.  
  15. System.out.println("Please enter your second number");
  16. Scanner Scanner2 = new Scanner (System.in);
  17. int secondInteger = Scanner2.nextInt();
  18.  
  19. System.out.println("Please enter the operation");
  20. Scanner Scanner3 = new Scanner (System.in);
  21. String operation =Scanner3.next();
  22.  
  23. if (operation == ("+")){
  24.  
  25. int answer = (firstInteger+secondInteger);
  26.  
  27. System.out.print(answer);
  28.  
  29. }
  30.  
  31. if (operation == ("-")) {
  32.  
  33. int answer = (firstInteger-secondInteger);
  34.  
  35. System.out.print(answer);
  36.  
  37. }
  38.  
  39. if (operation == ("*")) {
  40.  
  41. int answer = (firstInteger*secondInteger);
  42.  
  43. System.out.print(answer);
  44.  
  45.  
  46. }
  47.  
  48. if (operation == ("/")) {
  49.  
  50. int answer = (firstInteger/secondInteger);
  51.  
  52. System.out.print(answer);
  53.  
  54.  
  55. }
  56.  
  57.  
  58. Scanner1.close();
  59. Scanner2.close();
  60. Scanner3.close();
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment