View difference between Paste ID: cgnQCYEQ and GgQEtMmp
SHOW: | | - or go back to the newest paste.
1
package Exam_24_04_2016;
2
3
import java.util.Scanner;
4
5
/**
6
 * Created by todor on 13.03.2017 г..
7
 */
8
public class P03 {
9
    public static void main(String[] args) {
10
        Scanner scan = new Scanner(System.in);
11
        int num1 = Integer.parseInt(scan.nextLine());
12
        int num2 = Integer.parseInt(scan.nextLine());
13
        char operator = scan.nextLine().charAt(0);
14
        double result = 0;
15
    
16
        if (num2 == 0 && (operator == '/' || operator == '%')) {
17
            System.out.printf("Cannot divide %d by zero", num1);
18
            return;
19
        }
20
        
21
        switch (operator) {
22
            case '+':
23
                result = num1 + num2;
24
                break;
25
            case '-':
26
                result = num1 - num2;
27-
                if (num2 == 0) {
27+
28-
                    System.out.printf("Cannot divide %d by zero", num1);
28+
29-
                    return;
29+
30-
                }
30+
31
            case '/':
32
                result = (double) num1 / num2;
33
                System.out.printf("%d / %d = %.2f", num1, num2, result);
34
                return;
35-
                if (num2 == 0) {
35+
36-
                    System.out.printf("Cannot divide %d by zero", num1);
36+
37-
                    return;
37+
38-
                }
38+
39
                return;
40
        }
41
        
42
        String oddEven = result % 2 == 0 ?  "even" : "odd";
43
        System.out.printf("%d %s %d = %.0f - %s", num1, operator, num2, result, oddEven);
44
    }
45-
        System.out.printf("%d %s %d = %.0f - %s", num1, operator, num2, result, oddOrEven((int) result));
45+