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