Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n1 = Integer.parseInt(scanner.nextLine());
- int n2 = Integer.parseInt(scanner.nextLine());
- String operator = scanner.nextLine();
- double result = 0;
- if ("+".equals(operator)) {
- result = n1 + n2;
- if (result % 2 == 0) {
- System.out.printf("%d + %d = %.0f - even", n1, n2, result);
- } else if (result % 2 == 1) {
- System.out.printf("%d + %d = %.0f - odd", n1, n2, result);
- }
- } else if ("-".equals(operator)) {
- result = n1 - n2;
- if (result % 2 == 0) {
- System.out.printf("%d - %d = %.0f - even", n1, n2, result);
- } else if (result % 2 == 1) {
- System.out.printf("%d - %d = %.0f - odd", n1, n2, result);
- }
- } else if ("*".equals(operator)) {
- result = n1 * n2;
- if (result % 2 == 0) {
- System.out.printf("%d * %d = %.0f - even", n1, n2, result);
- } else if (result % 2 == 1) {
- System.out.printf("%d * %d = %.0f - odd", n1, n2, result);
- }
- } else if (n2 == 0 || n1 == 0) {
- System.out.printf("Cannot divide %d by zero", Math.max(n1, n2));
- } else if ("/".equals(operator)) {
- result = (double) n1 / (double) n2;
- System.out.printf("%d / %d = %.2f", n1, n2, result);
- } else if ("%".equals(operator)) {
- result = n1 % n2;
- System.out.println(n1 + " % " + n2 + " = " + (int) result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement