Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int num1 = Integer.parseInt(scanner.nextLine());
- int num2 = Integer.parseInt(scanner.nextLine());
- String symbol = scanner.nextLine();
- double result = 0;
- switch (symbol) {
- case "+":
- result = num1 + num2;
- break;
- case "-":
- result = num1 - num2;
- break;
- case "*":
- result = num1 * num2;
- break;
- case "/":
- if(num2 != 0) {
- result = (double) num1 / num2;
- }else {
- System.out.println("Cannot divide " + num1 + " by zero");
- }
- break;
- case "%":
- if(num2 != 0) {
- result = num1 % num2;
- }else {
- System.out.println("Cannot divide " + num1 + " by zero");
- }
- break;
- }
- if(symbol.equals("+") || symbol.equals("-") || symbol.equals("*")) {
- if(result % 2 == 0) {
- System.out.println(num1 + " " + symbol + " " + num2 + " = " + String.format("%.0f",result) + " - even");
- }else {
- System.out.println(num1 + " " + symbol + " " + num2 + " = " + String.format("%.0f",result) + " - odd");
- }
- }else if(symbol.equals("/") || symbol.equals("%")) {
- if(num2 != 0) {
- System.out.println(num1 + " " + symbol + " " + num2 + " = " + result);
- }
- }
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement