Advertisement
MladenKarachanov

Untitled

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