Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Exersice3 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double N1 = Double.parseDouble(scanner.nextLine());
- double N2 = Double.parseDouble(scanner.nextLine());
- double result = 0;
- String operator = scanner.nextLine();
- if ("+".equals(operator)) {
- result = N1 + N2;
- if (result % 2 == 0) {
- System.out.printf("%.0f + %.0f = %.0f - even", N1, N2, result);
- } else {
- System.out.printf("%.0f + %.0f = %.0f - odd", N1, N2, result);
- }
- } else if ("-".equals(operator)) {
- result = N1 - N2;
- if (result % 2 == 0) {
- System.out.printf("%.0f - %.0f = %.0f - even", N1, N2, result);
- } else {
- System.out.printf("%.0f - %.0f = %.0f - odd", N1, N2, result);
- }
- } else if ("*".equals(operator)) {
- result = N1 * N2;
- if (result % 2 == 0) {
- System.out.printf("%.0f * %.0f = %.0f - even", N1, N2, result);
- } else {
- System.out.printf("%.0f * %.0f = %.0f - odd", N1, N2, result);
- }
- } else if ("/".equals(operator)) {
- result = N1 / N2;
- if (N2 == 0) {
- System.out.printf("Cannot divide %.0f by zero", N1);
- }else {
- System.out.printf("%.0f / %.0f = %.2f", N1, N2, result);
- }
- } else if ("%".equals(operator)) {
- result = N1 % N2;
- if(N2 == 0) {
- System.out.printf("Cannot divide %.0f by zero", N1);
- }else {
- System.out.printf("%.0f %% %.0f = %.0f", N1, N2, result);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement