Advertisement
SIRAKOV4444

Untitled

Apr 4th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exersice3 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double N1 = Double.parseDouble(scanner.nextLine());
  8. double N2 = Double.parseDouble(scanner.nextLine());
  9. double result = 0;
  10. String operator = scanner.nextLine();
  11.  
  12.  
  13. if ("+".equals(operator)) {
  14. result = N1 + N2;
  15. if (result % 2 == 0) {
  16. System.out.printf("%.0f + %.0f = %.0f - even", N1, N2, result);
  17. } else {
  18. System.out.printf("%.0f + %.0f = %.0f - odd", N1, N2, result);
  19. }
  20.  
  21. } else if ("-".equals(operator)) {
  22. result = N1 - N2;
  23. if (result % 2 == 0) {
  24. System.out.printf("%.0f - %.0f = %.0f - even", N1, N2, result);
  25. } else {
  26. System.out.printf("%.0f - %.0f = %.0f - odd", N1, N2, result);
  27. }
  28. } else if ("*".equals(operator)) {
  29. result = N1 * N2;
  30. if (result % 2 == 0) {
  31. System.out.printf("%.0f * %.0f = %.0f - even", N1, N2, result);
  32. } else {
  33. System.out.printf("%.0f * %.0f = %.0f - odd", N1, N2, result);
  34. }
  35. } else if ("/".equals(operator)) {
  36. result = N1 / N2;
  37. if (N2 == 0) {
  38. System.out.printf("Cannot divide %.0f by zero", N1);
  39. }else {
  40. System.out.printf("%.0f / %.0f = %.2f", N1, N2, result);
  41. }
  42.  
  43. } else if ("%".equals(operator)) {
  44. result = N1 % N2;
  45. if(N2 == 0) {
  46. System.out.printf("Cannot divide %.0f by zero", N1);
  47. }else {
  48. System.out.printf("%.0f %% %.0f = %.0f", N1, N2, result);
  49. }
  50. }
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement