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