velikova_olya

Operations

Feb 2nd, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. package ComplexCondStatExams;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class OperationsBetweenNumbers {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. double N1 = Double.parseDouble(scanner.nextLine());
  10. double N2 = Double.parseDouble(scanner.nextLine());
  11. String operator = scanner.nextLine();
  12.  
  13. double operation = 0;
  14.  
  15. if (operator.equals("+")) {
  16. operation = N1 + N2;
  17. } else if (operator.equals("-")) {
  18. operation = N1 - N2;
  19. } else if (operator.equals("*")) {
  20. operation = N1 * N2;
  21. } else if (operator.equals("/")) {
  22. operation = N1 / N2;
  23. } else if (operator.equals("%")) {
  24. operation = N1 % N2;
  25. }
  26.  
  27. if (operator.equals("+") || operator.equals("-") || operator.equals("*")) {
  28. if (operation % 2 == 0) {
  29. System.out.printf("%.0f %s %.0f = %.0f - even", N1, operator, N2, operation);
  30. } else {
  31. System.out.printf("%.0f %s %.0f = %.0f - odd", N1, operator, N2, operation);
  32. }
  33. } else if (operator.equals("/")) {
  34. if (N2 == 0) {
  35. System.out.printf("Cannot divide %0.f by zero", N1);
  36. } else {
  37. System.out.printf("%.0f %s %.0f = %.2f", N1, operator, N2, operation);
  38. }
  39. } else if (operator.equals("%")) {
  40. if (N2 == 0) {
  41. System.out.printf("Cannot divide %.0f by zero", N1);
  42. } else {
  43. System.out.printf("%.0f %s %.0f = %.0f", N1, operator, N2, operation);
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment