Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EvenOddProduct {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n=Integer.parseInt(scanner.nextLine());
- String line = scanner.nextLine();
- String[] arr= line.split(" ");
- int[] newArr=new int[n];
- int productOfEven=1;
- int productOfOdd=1;
- for (int i = 0; i < newArr.length ; i++) {
- newArr[i]=Integer.parseInt(arr[i]);
- if (i%2==0) {
- productOfEven=productOfEven*newArr[i];
- }
- else {
- productOfOdd=productOfOdd*newArr[i];
- }
- }
- if (productOfEven==productOfOdd) {
- System.out.printf("Yes %d",productOfEven).println();
- }
- else {
- System.out.printf("No %d %d",productOfEven,productOfOdd);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement