Advertisement
valiamaximova1

sum numbers

May 13th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ex3 {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6. int num1 = Integer.parseInt(scan.nextLine());
  7. int num2 = Integer.parseInt(scan.nextLine());
  8. String operation = scan.nextLine();
  9. double result = 0;
  10. switch (operation) {
  11. case "sum":
  12. result = num1 + num2;
  13. break;
  14. case "sub":
  15. result = Math.abs(num1 - num2);
  16. break;
  17. case "mul":
  18. result = num1 * num2;
  19. break;
  20. case "div":
  21. result = num1*1.0 / num2;
  22. break;
  23. }
  24. System.out.println(result);
  25. }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement