Advertisement
Guest User

Untitled

a guest
Aug 27th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. // @author Roner Reked
  5.  
  6. public class Calculator {
  7.  
  8. public static void main(String[] args) {
  9.  
  10. int x, y;
  11. String format;
  12.  
  13. Scanner z = new Scanner(System.in);
  14. System.out.println("Ange tal 1: ");
  15. x = z.nextInt();
  16. System.out.println("Ange tal 2: ");
  17. y = z.nextInt();
  18.  
  19.  
  20. System.out.println("Ange +, -, /, *");
  21. format = z.next();
  22.  
  23. switch (format) {
  24.  
  25. case "+":
  26. System.out.println("" + x + " + " + y + " = " + (x + y));
  27. break;
  28. case "-":
  29. System.out.println("" + x + " - " + y + " = " + (x - y));
  30. break;
  31. case "/":
  32. if (y == 0) {
  33. System.out.println("Cannot divide by zero, try again.");
  34. return;
  35. }
  36. System.out.println("" + x + " / " + y + " = " + (x / y));
  37. break;
  38. case "*":
  39. System.out.println("" + x + " * " + y + " = " + (x * y));
  40. break;
  41. default:
  42. System.out.println("Syntax: + - * /");
  43.  
  44. }
  45.  
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement