Advertisement
VelizarR

Odd and Even Product

Nov 2nd, 2021
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. public class OddEvenProduct {
  2.     public static void main(String[] args) {
  3.  
  4.         Scanner scanner = new Scanner(System.in);
  5.         int n = Integer.parseInt(scanner.nextLine());
  6.  
  7.         int line = n;
  8.         int odd = 1;
  9.         int even = 1;
  10.  
  11.         for (int i = 1; i <= n; i++) {
  12.             int digit = Integer.parseInt(scanner.nextLine());
  13.             if (line % 2 == 1){
  14.                 odd *= digit;
  15.             }
  16.             else {
  17.                 even *= digit;
  18.             }
  19.             line -= 1;
  20.         }
  21.         if ( odd == even){
  22.             System.out.println("yes " + odd);
  23.         }
  24.         else {
  25.             System.out.println("no " + odd + " " + even);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement