AsyaDamyanova

Operations Between Numbers

Oct 31st, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 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.         double N1 = Double.parseDouble(scanner.nextLine());
  7.         double N2 = Double.parseDouble(scanner.nextLine());
  8.         char operation = scanner.nextLine().charAt(0);
  9.         double result = 0.00;
  10.  
  11.         switch (operation) {
  12.             case '+':
  13.                 result = N1 + N2;
  14.                 if (result % 2 == 0) {
  15.                     System.out.printf("%.0f %c %.0f = %.0f - even", N1, operation, N2, result);
  16.                 } else {
  17.                     System.out.printf("%.0f %c %.0f = %.0f - odd", N1, operation, N2, result);
  18.                 }
  19.                 break;
  20.             case '-':
  21.                 result = N1 - N2;
  22.                 if (result % 2 == 0) {
  23.                     System.out.printf("%.0f %c %.0f = %.0f - even", N1, operation, N2, result);
  24.                 } else {
  25.                     System.out.printf("%.0f %c %.0f = %.0f - odd", N1, operation, N2, result);
  26.                 }
  27.                 break;
  28.             case '*':
  29.                 result = N1 * N2;
  30.                 if (result % 2 == 0) {
  31.                     System.out.printf("%.0f %c %.0f = %.0f - even", N1, operation, N2, result);
  32.                 } else {
  33.                     System.out.printf("%.0f %c %.0f = %.0f - odd", N1, operation, N2, result);
  34.                 }
  35.                 break;
  36.             case '/':
  37.                 result = N1 / N2;
  38.                 if (N2 != 0) {
  39.                     System.out.printf("%.0f %c %.0f = %.2f", N1, operation, N2, result);
  40.                 } else {
  41.                     System.out.printf("Cannot divide %.0f by zero", N1);
  42.                 }
  43.                 break;
  44.             case '%':
  45.                 result = N1 % N2;
  46.                 if (N2 != 0) {
  47.                     System.out.printf("%.0f %c %.0f = %.0f", N1, operation, N2, result);
  48.                 } else {
  49.                     System.out.printf("Cannot divide %.0f by zero", N1);
  50.                 }
  51.                 break;
  52.  
  53.  
  54.         }
  55.  
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment