Advertisement
paykova

OddEvenPosition

Oct 11th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OddEvenPosition {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int n = Integer.parseInt(scanner.nextLine());
  8. String no = "No";
  9.  
  10. double oddSum = 0;
  11. double oddMin = Integer.MAX_VALUE;
  12. double oddMax = Integer.MIN_VALUE;
  13.  
  14. double evenSum = 0;
  15. double evenMin = Integer.MAX_VALUE;
  16. double evenMax = Integer.MIN_VALUE;
  17.  
  18. for (int i = 1; i <= n; i++) {
  19.  
  20. double num = Double.parseDouble(scanner.nextLine());
  21.  
  22. if (i % 2 != 0) {
  23. oddSum += num;
  24. if (num < oddMin) {
  25. oddMin = num;
  26. }
  27. if (num > oddMax) {
  28. oddMax = num;
  29. }
  30.  
  31. } else if (i % 2 == 0) {
  32. evenSum += num;
  33. if (num < evenMin) {
  34. evenMin = num;
  35. }
  36. if (num > evenMax) {
  37. evenMax = num;
  38. }
  39. }
  40. }
  41. System.out.println("OddSum = "+oddSum);
  42. System.out.println("OddMin = "+oddMin);
  43. System.out.println("OddMax = "+oddMax);
  44. System.out.println("EvenSum = "+evenSum);
  45. System.out.println("EvenMin = "+evenMin);
  46. System.out.println("EvenMax = "+evenMax);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement