Advertisement
Guest User

Loop

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