BapBapuHa

odd/even position

Feb 2nd, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         double count = Double.parseDouble(scanner.nextLine());
  10.         double oddSum = 0;
  11.         double oddMin = 1000000000.0;
  12.         double oddMax = -1000000000.0;
  13.         double evenSum = 0;
  14.         double evenMin = 1000000000.0;
  15.         double evenMax = -1000000000.0;
  16.         for (int i = 1; i <= count; i++) {
  17.             double current = Double.parseDouble(scanner.nextLine());
  18.             if (i % 2 == 0) {
  19.                 evenSum += current;
  20.                 if (current < evenMin) {
  21.                     evenMin = current;
  22.                 }
  23.                 if (current > evenMax) {
  24.                     evenMax = current;
  25.                 }
  26.             } else {
  27.                 oddSum += current;
  28.                 if (current < oddMin) {
  29.                     oddMin = current;
  30.                 }
  31.                 if (current > oddMax) {
  32.                     oddMax = current;
  33.  
  34.                 }
  35.             }
  36.         }
  37.         System.out.printf("OddSum=%.2f,%n", oddSum);
  38.         if (oddMin == 1000000000.0) {
  39.             System.out.printf("OddMin=No,%n");
  40.         } else {
  41.             System.out.printf("OddMin=%.2f,%n", oddMin);
  42.         }
  43.         if (oddMax == -1000000000.0) {
  44.             System.out.printf("OddMax=No,%n");
  45.         } else {
  46.             System.out.printf("OddMax=%.2f,%n", oddMax);
  47.         }
  48.         System.out.printf("EvenSum=%.2f,%n", evenSum);
  49.         if (evenMin == 1000000000.0) {
  50.             System.out.printf("EvenMin=No,%n");
  51.         } else {
  52.             System.out.printf("EvenMin=%.2f,%n", evenMin);
  53.         }
  54.         if (evenMax == -1000000000.0) {
  55.             System.out.printf("EvenMax=No%n");
  56.         } else {
  57.             System.out.printf("EvenMax=%.2f%n", evenMax);
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment