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);
- int N1 = Integer.parseInt(scanner.nextLine());
- int N2 = Integer.parseInt(scanner.nextLine());
- String operator = scanner.nextLine();
- // double result = 0;
- switch (operator) {
- case "+":
- if ((N1 + N2) % 2 == 0) {
- System.out.printf("%d %s %d = %d - even", N1, operator, N2, N1 + N2);
- } else if ((N1 + N2) % 2 != 0) {
- System.out.printf("%d %s %d = %d - odd", N1, operator, N2, N1 + N2);
- }
- break;
- case "-":
- if ((N1 - N2) % 2 == 0) {
- System.out.printf("%d %s %d = %d - even", N1, operator, N2, N1 - N2);
- } else if ((N1 - N2) % 2 != 0) {
- System.out.printf("%d %s %d = %d - odd", N1, operator, N2, N1 - N2);
- }
- break;
- case "*":
- if ((N1 * N2) % 2 == 0) {
- System.out.printf("%d %s %d = %d - even", N1, operator, N2, N1 * N2);
- } else if ((N1 * N2) % 2 != 0) {
- System.out.printf("%d %s %d = %d - odd", N1, operator, N2, N1 * N2);
- }
- break;
- case "/":
- if (N2 == 0) {
- System.out.printf("Cannot divide %d by zero", N1);
- } else {
- System.out.printf("%d %s %d = %.2f", N1, operator, N2, (double)N1 / (double) N2);
- }
- break;
- case "%":
- if (N2 == 0) {
- System.out.printf("Cannot divide %d by zero", N1);
- } else {
- System.out.printf("%d %s %d = %.0f", N1, operator, N2, (double)N1 % (double) N2);
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment