Advertisement
KeepCoding

Odd / Even Position

Nov 7th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class Wat {
  5.     public static void main(String[] args) {
  6.         Scanner console = new Scanner(System.in);
  7.         DecimalFormat df = new DecimalFormat("#.#######");
  8.         int n = Integer.parseInt(console.nextLine());
  9.         double oddSum = 0.0;
  10.         double oddMin = Double.MAX_VALUE;
  11.         double oddMax = -Double.MAX_VALUE;
  12.         double evenSum = 0.0;
  13.         double evenMin = Double.MAX_VALUE;
  14.         double evenMax = -Double.MAX_VALUE;
  15.  
  16.         for (int i = 1; i <= n; i++) {
  17.             double currentNumber = Double.parseDouble(console.nextLine());
  18.             if (i % 2 == 0) {
  19.                 evenSum += currentNumber;
  20.                 if (currentNumber >= evenMax) {
  21.                     evenMax = currentNumber;
  22.                 }
  23.                 if (currentNumber <= evenMin) {
  24.                     evenMin = currentNumber;
  25.                 }
  26.             } else {
  27.                 oddSum += currentNumber;
  28.                 if (currentNumber >= oddMax) {
  29.                     oddMax = currentNumber;
  30.                 }
  31.                 if (currentNumber <= oddMin) {
  32.                     oddMin = currentNumber;
  33.                 }
  34.             }
  35.         }
  36.  
  37.         System.out.println("OddSum = " + df.format(oddSum));
  38.  
  39.         if (oddMin != Double.MAX_VALUE) {
  40.             System.out.println("OddMin = " + df.format(oddMin));
  41.         } else {
  42.             System.out.println("OddMin no");
  43.         }
  44.  
  45.         if (oddMax != -Double.MAX_VALUE) {
  46.             System.out.println("OddMax = " + df.format(oddMax));
  47.         } else {
  48.             System.out.println("OddMax no");
  49.         }
  50.  
  51.  
  52.  
  53.         System.out.println("EvenSum = " + df.format(evenSum));
  54.  
  55.         if (evenMin != Double.MAX_VALUE) {
  56.             System.out.println("EvenMin = " + df.format(evenMin));
  57.         } else {
  58.             System.out.println("EvenMin no");
  59.         }
  60.  
  61.         if (evenMax != -Double.MAX_VALUE) {
  62.             System.out.println("EvenMax = " + df.format(evenMax));
  63.         } else {
  64.             System.out.println("EvenMax no");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement