Advertisement
cvet40

Odd / Even Position

Feb 4th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. package e_SimpleLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class p11_OddAndEvenPositionMY {
  6. public static void main(String[] args) {
  7. Scanner scan = new Scanner(System.in);
  8. int count = Integer.parseInt(scan.nextLine());
  9.  
  10. double oddSum = 0;
  11. double oddMax = -1000000000.0;
  12. double oddMin = 1000000000.0;
  13.  
  14. double evenSum = 0;
  15. double evenMax = -1000000000.0;
  16. double evenMin = 1000000000.0;
  17.  
  18. for (int i = 1; i <= count; i++) {
  19. double currentNum = Double.parseDouble(scan.nextLine());
  20. if (i % 2 == 0) {
  21. evenSum += currentNum;
  22. if (currentNum > evenMax) {
  23. evenMax = currentNum;
  24. }
  25. if (currentNum < evenMin) {
  26. evenMin = currentNum;
  27.  
  28. }
  29.  
  30. } else {
  31. oddSum += currentNum;
  32. if (currentNum > oddMax) {
  33. oddMax = currentNum;
  34. }
  35. if (currentNum < oddMin) {
  36. oddMin = currentNum;
  37.  
  38. }
  39.  
  40. }
  41.  
  42. }
  43. if (oddSum % 1 == 0.0) {
  44. System.out.printf("OddSum=%s,%n", Integer.toString((int)oddSum));
  45. } else {
  46. System.out.printf("OddSum=%s,%n", Double.toString(oddSum));
  47. }
  48. if (oddMin == 1000000000.0) {
  49. System.out.println("OddMin=No,");
  50. } else if (oddMin % 1 == 0.0) {
  51. System.out.printf("OddMin=%s,%n", Integer.toString((int)oddMin));
  52. } else {
  53. System.out.printf("OddMin=%s,%n", Double.toString(oddMin));
  54. }
  55. if (oddMax == -1000000000.0) {
  56. System.out.println("OddMax=No,");
  57. } else if (oddMax % 1 == 0.0) {
  58. System.out.printf("OddMax=%s,%n", Integer.toString((int)oddMax));
  59. } else {
  60. System.out.printf("OddMax=%s,%n", Double.toString(oddMax));
  61. }
  62. if (evenSum % 1 == 0.0) {
  63. System.out.printf("EvenSum=%s,%n", Integer.toString((int)evenSum));
  64. } else {
  65. System.out.printf("EvenSum=%s,%n", Double.toString(evenSum));
  66. }
  67. if (evenMin == 1000000000.0) {
  68. System.out.println("EvenMin=No,");
  69. } else if (evenMin % 1 == 0.0) {
  70. System.out.printf("EvenMin=%s,%n", Integer.toString((int)evenMin));
  71. } else {
  72. System.out.printf("EvenMin=%s,%n", Double.toString(evenMin));
  73. }
  74. if (evenMax == -1000000000.0) {
  75. System.out.println("EvenMax=No,");
  76. } else if (evenMax % 1 == 0.0) {
  77. System.out.printf("EvenMax=%s,%n", Integer.toString((int)evenMax));
  78. } else {
  79. System.out.printf("EvenMax=%s,%n", Double.toString(evenMax));
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement