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