Advertisement
Guest User

Untitled

a guest
Dec 6th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. //Tan, Benz Walter Jacques C.
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Tan_Switch
  6. {
  7. public static void main(String args[])
  8. {
  9. Scanner sc = new Scanner(System.in);
  10. System.out.println("\nCALCULATOR:\n");
  11. System.out.print("Input 1st Number: ");
  12. float input_1= sc.nextInt();
  13. System.out.print("Input 2nd Number: ");
  14. float input_2= sc.nextInt();
  15. System.out.print("Input Operator(+,-,*,/): ");
  16. float answer = 0;
  17. char operator = sc.next().charAt(0);
  18. boolean print = true;
  19.  
  20. switch(operator)
  21. {
  22. case '+': answer = input_1 + input_2; break;
  23.  
  24. case '-': answer = input_1 - input_2; break;
  25.  
  26. case '*': answer = input_1 * input_2; break;
  27.  
  28. case '/': answer = input_1 / input_2; break;
  29.  
  30. default: System.out.println("Invalid Operation"); print = false; break;
  31. }
  32.  
  33. if(print==true)
  34. {
  35. System.out.println("The Answer of " + input_1 + " " + operator + " " + input_2 + " = " + answer);
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement