Advertisement
MladenKarachanov

Untitled

Oct 7th, 2022
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 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. Scanner scanner = new Scanner(System.in);
  8.  
  9. int N1 = Integer.parseInt(scanner.nextLine());
  10. int N2 = Integer.parseInt(scanner.nextLine());
  11. String operator = scanner.nextLine();
  12.  
  13. int result = 0;
  14.  
  15.  
  16. if ("+".equals(operator)) {
  17. result = N1 + N2;
  18. if (result % 2 == 0) {
  19. System.out.printf("%d + %d = %d - even", N1, N2, result);
  20. } else {
  21. System.out.printf("%d + %d = %d - odd", N1, N2, result);
  22. }
  23. } else if ("-".equals(operator)) {
  24. result = N1 + N2;
  25. if (result % 2 == 0) {
  26. System.out.printf("%d - %d = %d - even", N1, N2, result);
  27. } else {
  28. System.out.printf("%d - %d = %d - odd", N1, N2, result);
  29. }
  30. } else if ("*".equals(operator)) {
  31. result = N1 * N2;
  32. if (result % 2 == 0) {
  33. System.out.printf("%d * %d = %d - even", N1, N2, result);
  34. } else {
  35. System.out.printf("%d * %d = %d - odd", N1, N2, result);
  36. }
  37. } else if ("/".equals(operator)) {
  38. result = N1 / N2 ;
  39. if (N2 != 0) {
  40. System.out.printf("%d / %d = %.2f", N1, N2, result);
  41. } else {
  42. System.out.printf("Cannot divide %d by zero", N1);
  43. }
  44. } else if ("%".equals(operator)) {
  45. result = N1 % N2;
  46. if (N2 != 0) {
  47. System.out.printf("%d %% %d = %d", N1, N2, result);
  48. } else {
  49. System.out.printf("Cannot divide %d by zero", N1);
  50. }
  51. }
  52.  
  53. System.out.println(result);
  54.  
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement