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