Advertisement
webd

OddOrEvenProduct

Apr 26th, 2022
46
294 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class OddOrEvenProduct {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         Scanner scan = new Scanner(System.in);
  7.         int n = Integer.parseInt(scan.nextLine());
  8.         String x = scan.nextLine();
  9.         String[] input = x.split(" ");
  10.         int[] array = new int[input.length];
  11.         int evenProduct = 1;
  12.         int oddProduct = 1;
  13.  
  14.         for (int i = 0; i < n ; i++) {
  15.             array[i] = Integer.parseInt(input[i]);
  16.             if (i % 2 == 0) {
  17.                 evenProduct *= array[i];
  18.             } else {
  19.                 oddProduct *= array[i];
  20.             }
  21.         }
  22.         if (evenProduct == oddProduct) {
  23.             System.out.printf("yes %d", evenProduct);
  24.         }    else {
  25.             System.out.printf("no %d %d", evenProduct , oddProduct);
  26.         }
  27.     }
  28. }
Advertisement
RAW Paste Data Copied
Advertisement