Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class xxx {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double n1 = Double.parseDouble(scanner.nextLine());
- double n2 = Double.parseDouble(scanner.nextLine());
- char operators = scanner.nextLine().charAt(0);
- double result = 0.0;
- switch (operators) {
- case '+':
- result = n1 + n2;
- if (result % 2 == 0) {
- System.out.printf("%.0f + %.0f = %.0f - even", n1, n2, result);
- } else {
- System.out.printf("%.0f + %.0f = %.0f - odd", n1, n2, result);
- }
- break;
- case '-':
- result = n1 - n2;
- if (result % 2 == 0) {
- System.out.printf("%.0f - %.0f = %.0f - even", n1, n2, result);
- } else {
- System.out.printf("%.0f - %.0f = %.0f - odd", n1, n2, result);
- }
- break;
- case '*':
- result = n1 * n2;
- if (result % 2 == 0) {
- System.out.printf("%.0f * %.0f = %.0f - even", n1, n2, result);
- } else {
- System.out.printf("%.0f * %.0f = %.0f - odd", n1, n2, result);
- }
- break;
- case '/':
- if (n2 == 0) {
- System.out.printf("Cannot divide %.0f by zero",n1);
- } else {
- result = n1 / n2;
- System.out.printf("%.0f / %.0f = %.2f", n1, n2, result);
- }
- break;
- case '%':
- if (n2 == 0) {
- System.out.printf("Cannot divide %.0f by zero",n1);
- } else {
- result = n1 % n2;
- System.out.printf("%.0f %% %.0f = %.0f", n1, n2, result);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement