Advertisement
silviasj

operations between numbers

Mar 18th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class operationsBetweenNumbers {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int N1 = Integer.parseInt(scanner.nextLine());
  8.         int N2 = Integer.parseInt(scanner.nextLine());
  9.         char operator = scanner.nextLine().charAt(0);
  10.  
  11.         int result1 = N1 + N2;
  12.         int result2 = N1 - N2;
  13.         int result3 = N1 * N2;
  14.         double result4 = N1 * 1.0 / N2;
  15.         int result5 = N1 % N2;
  16.  
  17.  
  18.         if (operator == '+') {
  19.             if (result1 % 2 == 0) {
  20.                 System.out.printf("%d %c %d = %d – even", N1, operator, N2, result1);
  21.             } else {
  22.                 System.out.printf("%d %c %d = %d – odd", N1, operator, N2, result1);
  23.             }
  24.         }
  25.         if (operator == '-') {
  26.             if (result2 % 2 == 0) {
  27.                 System.out.printf("%d %c %d = %d – even", N1, operator, N2, result2);
  28.             } else {
  29.                 System.out.printf("%d %c %d = %d – odd", N1, operator, N2, result2);
  30.             }
  31.         }
  32.  
  33.         if (operator == '*') {
  34.             if (result3 % 2 == 0) {
  35.                 System.out.printf("%d %c %d = %d – even", N1, operator, N2, result3);
  36.             } else {
  37.                 System.out.printf("%d %c %d = %d – odd", N1, operator, N2, result3);
  38.             }
  39.         }
  40.         if (operator == '/') {
  41.             if (N2 == 0) {
  42.                 System.out.printf("Cannot divide %d by zero", N1);
  43.             } else {
  44.                 System.out.printf("%d %c %d = %.2f", N1, operator, N2, result4);
  45.             }
  46.         }
  47.         if (operator == '%') {
  48.             if (N2 == 0) {
  49.                 System.out.printf("Cannot divide %d by zero", N1);
  50.             } else {
  51.                 System.out.printf("%d %c %d = %d", N1, operator, N2, result5);
  52.             }
  53.  
  54.  
  55.         }
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement