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());
- char operator = scanner.nextLine().charAt(0);
- int result1 = N1 + N2;
- int result2 = N1 - N2;
- int result3 = N1 * N2;
- double result4 = N1 * 1.0 / N2;
- int result5 = N1 % N2;
- if (operator == '+') {
- if (result1 % 2 == 0) {
- System.out.printf("%d %c %d = %d – even", N1, operator, N2, result1);
- } else {
- System.out.printf("%d %c %d = %d – odd", N1, operator, N2, result1);
- }
- }
- if (operator == '-') {
- if (result2 % 2 == 0) {
- System.out.printf("%d %c %d = %d – even", N1, operator, N2, result2);
- } else {
- System.out.printf("%d %c %d = %d – odd", N1, operator, N2, result2);
- }
- }
- if (operator == '*') {
- if (result3 % 2 == 0) {
- System.out.printf("%d %c %d = %d – even", N1, operator, N2, result3);
- } else {
- System.out.printf("%d %c %d = %d – odd", N1, operator, N2, result3);
- }
- }
- if (operator == '/') {
- if (N2 == 0) {
- System.out.printf("Cannot divide %d by zero", N1);
- } else {
- System.out.printf("%d %c %d = %.2f", N1, operator, N2, result4);
- }
- }
- if (operator == '%') {
- if (N2 == 0) {
- System.out.printf("Cannot divide %d by zero", N1);
- } else {
- System.out.printf("%d %c %d = %d", N1, operator, N2, result5);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement