Advertisement
Guest User

Array

a guest
Oct 27th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class EvenOddProduct {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int n=Integer.parseInt(scanner.nextLine());
  9.  
  10. String line = scanner.nextLine();
  11. String[] arr= line.split(" ");
  12.  
  13. int[] newArr=new int[n];
  14. int productOfEven=1;
  15. int productOfOdd=1;
  16. for (int i = 0; i < newArr.length ; i++) {
  17. newArr[i]=Integer.parseInt(arr[i]);
  18. if (i%2==0) {
  19. productOfEven=productOfEven*newArr[i];
  20. }
  21. else {
  22. productOfOdd=productOfOdd*newArr[i];
  23. }
  24. }
  25.  
  26. if (productOfEven==productOfOdd) {
  27. System.out.printf("Yes %d",productOfEven).println();
  28. }
  29. else {
  30. System.out.printf("No %d %d",productOfEven,productOfOdd);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement