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