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