Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OperationsBetweenNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double num1 = Double.parseDouble(scanner.nextLine());
- double num2 = Double.parseDouble(scanner.nextLine());
- String symbol = scanner.nextLine();
- double result = 0;
- if (symbol.equals("+")) {
- result = num1 + num2;
- if (result % 2 == 0) {
- System.out.printf("%.0f + %.0f = %.0f - even", num1, num2, result);
- } else if (result % 2 == 1) {
- System.out.printf("%.0f + %.0f = %.0f - odd", num1, num2, result);
- }
- } else if (symbol.equals("-")) {
- result = num1 - num2;
- if (result % 2 == 0) {
- System.out.printf("%.0f - %.0f = %.0f - even", num1, num2, result);
- } else if (result % 2 == 1) {
- System.out.printf("%.0f - %.0f = %.0f - odd", num1, num2, result);
- }
- } else if (symbol.equals("*")) {
- result = num1 * num2;
- if (result % 2 == 0) {
- System.out.printf("%.0f * %.0f = %.0f - even", num1, num2, result);
- } else if (result % 2 == 1) {
- System.out.printf("%.0f * %.0f = %.0f - odd", num1, num2, result);
- }
- } else if (symbol.equals("/")) {
- result = num1 / num2;
- String result2 = String.valueOf(result);
- if ((result2.equals("Infinity") || result2.equals("NaN"))) {
- System.out.printf("Cannot divide %.0f by zero", num1);
- } else {
- System.out.printf("%.0f / %.0f = %.2f", num1, num2, result);
- }
- } else if (symbol.equals("%")) {
- result = num1 % num2;
- String result3 = String.valueOf(result);
- if ((result3.equals("Infinity") || result3.equals("NaN"))) {
- System.out.printf("Cannot divide %.0f by zero", num1);
- } else {
- System.out.printf("%.0f %% %.0f = %.0f", num1, num2, result);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement