Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Project: Exam_24_April_2016 - created by borkins on 2017-05-16.
- */
- import java.util.Scanner;
- public class _03_OperationsBetweenNumbers
- {
- public static void main(String[] args)
- {
- Scanner console = new Scanner(System.in);
- int a = Integer.parseInt(console.nextLine());
- int b = Integer.parseInt(console.nextLine());
- String op = console.nextLine();
- if (b == 0 && (op.equals("/") || op.equals("%"))) {
- System.out.println("Cannot divide " + a + " by zero");
- } else if (op.equals("+")) {
- System.out.printf("%d + %d = %d - %s%n", a, b, (a + b), oddEven(a + b));
- } else if (op.equals("-")) {
- System.out.printf("%d - %d = %d - %s%n", a, b, (a - b), oddEven(a - b));
- } else if (op.equals("*")) {
- System.out.printf("%d * %d = %d - %s%n", a, b, (a * b), oddEven(a * b));
- } else if (op.equals("/")) {
- System.out.printf("%d / %d = %.2f%n", a, b, ((double) a / b));
- } else if (op.equals("%")) {
- System.out.printf("%d %% %d = %d%n", a, b, (a % b));
- }
- }
- public static String oddEven(int result) {
- return result % 2 == 0 ? "even" : "odd";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment