SvetlanPetrova

Multiplication Sign SoftUni

Jun 25th, 2021
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. import java.lang.reflect.Method;
  2. import java.util.Scanner;
  3.  
  4. public class MultiplicationSign {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         int num1 = Integer.parseInt(scanner.nextLine());
  8.         int num2 = Integer.parseInt(scanner.nextLine());
  9.         int num3 = Integer.parseInt(scanner.nextLine());
  10.  
  11.         if (isZero(num1, num2, num3)) {
  12.             System.out.println("zero");
  13.         }
  14.         else if (isNegative(num1, num2, num3)) {
  15.             System.out.println("negative");
  16.         }
  17.         else if (isPositive(num1, num2, num3)) {
  18.             System.out.println("positive");
  19.         }
  20.  
  21.     }
  22.  
  23.     private static boolean isNegative(int num1, int num2, int num3) {
  24.         int[] numbers = new int[]{num1, num2, num3};
  25.         int countNegative = 0;
  26.         for (int i = 0; i < numbers.length; i++) {
  27.             if (numbers[i] < 0) {
  28.                 countNegative++;
  29.             }
  30.         }
  31.         if (countNegative % 2 == 1) {
  32.             return true;
  33.         }
  34.         return false;
  35.     }
  36.  
  37.     private static boolean isZero(int num1, int num2, int num3) {
  38.         int[] numbers = new int[]{num1, num2, num3};
  39.         for (int i = 0; i < numbers.length; i++) {
  40.             if (numbers[i] == 0) {
  41.                 return true;
  42.             }
  43.         }
  44.         return false;
  45.     }
  46.  
  47.     private static boolean isPositive(int num1, int num2, int num3) {
  48.         int[] numbers = new int[]{num1, num2, num3};
  49.         int countNegative = 0;
  50.         for (int i = 0; i < numbers.length; i++) {
  51.             if (numbers[i] < 0) {
  52.                 countNegative++;
  53.             }
  54.         }
  55.         if (countNegative == 0 || countNegative == 2) {
  56.             return true;
  57.         }
  58.         return false;
  59.     }
  60.  
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment