Advertisement
riffersfeast

OddAndEvenProduct

Mar 7th, 2021
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OddAndEvenProduct {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int N = scanner.nextInt();
  7.         int evenProduct = 1;
  8.         int oddProduct = 1;
  9.  
  10.         for (int i = 1; i <= N; i++) {
  11.             int num = scanner.nextInt();
  12.             if (i % 2 == 0) {
  13.                 evenProduct = evenProduct * num;
  14.             }else {
  15.                 oddProduct = oddProduct * num;
  16.             }
  17.         }
  18.         if (evenProduct == oddProduct) {
  19.             System.out.printf("yes %d", evenProduct);
  20.         }else {
  21.             System.out.printf("no %d %d", oddProduct, evenProduct);
  22.         }
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement