Aleks_Tor

Odd and Even Product [first one]

May 6th, 2021
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int times = scanner.nextInt();
  7.         while (times-->0) {
  8.             int[] nums = new int[times+1];
  9.             for (int i = 0; i <times+1; i++) {
  10.                 nums[i] = scanner.nextInt();
  11.             }
  12.             int odds = 1;
  13.             int evens = 1;
  14.             for (int i = 0; i < nums.length; i += 2)
  15.                 odds *= nums[i];
  16.             for (int j = 1; j < nums.length - 1; j+=2)
  17.                 evens *= nums[j];
  18.             if (odds == evens) {
  19.                 System.out.println("yes "+odds);
  20.             } else {
  21.                 System.out.println("no"+" "+odds+" "+evens);
  22.             }
  23.         }
  24.     }
  25.     }
RAW Paste Data