Advertisement
IvaAnd

BetweenNumbers

Feb 28th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Operations_secondTry {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double N1 = Double.parseDouble(scanner.nextLine());
  8. int N2 = Integer.parseInt(scanner.nextLine());
  9. char symbol = scanner.nextLine().charAt(0);
  10. double result = 0;
  11.  
  12. if (symbol == '+') {
  13. result = N1 + N2;
  14. if (symbol == '-') {
  15. result = N1 - N2;
  16. } else if (symbol == '*') {
  17. result = N1 * N2;
  18. }
  19. if (result % 2 == 0) {
  20. String evenOrOdd = "even";
  21. } else {
  22. String evenOrOdd = "odd";
  23. System.out.printf("%.0f %c %d = %.0f - %s", N1, symbol, N2, result, evenOrOdd);
  24. }
  25. }
  26. if (symbol == '/') {
  27. if (N2 == 0) {
  28. System.out.printf("Cannot divide %.0f by zero", N1);
  29. } if (N2 != 0)
  30. result = N1 / N2;
  31. System.out.printf("%.0f %c %d = %.2f", N1, N2, result);
  32.  
  33. } else if (symbol == '%') {
  34. result = N1 % N2;
  35. System.out.printf("%.0f %c %d = %.0f", N1, N2, result);
  36.  
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement