Roadstar3

Operations

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