Aikihack

СофтУни Simple Loops 12. Equal Pairs

Apr 4th, 2017
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1.  
  2.  
  3. import java.util.Scanner;
  4.  
  5. /*** Created by AiKiHack on 03-04-2017 22:00 in project simpleLoops01042017 ***/
  6.  
  7. public class p_05_11_oddEvenPosition {
  8.     public static void main(String[] args) {
  9.         Scanner consolein = new Scanner(System.in);
  10.         int input = Integer.parseInt(consolein.nextLine());
  11.         String response = "";
  12.         double[] responseVal = 0.0;
  13.         double sumEven = 0.0;
  14.         double sumOdd = 0.0;
  15.         double minEven = Double.MAX_VALUE;
  16.         double minOdd = Double.MAX_VALUE;
  17.         double maxEven = Double.MIN_VALUE;
  18.         double maxOdd = Double.MIN_VALUE;
  19.  
  20.         for (int i = 0; i < input; i++) {
  21.             double in = Double.parseDouble(consolein.nextLine());
  22.             if(i % 2 == 0){
  23.                 sumEven += in;
  24.                 if(in > maxEven){maxEven = in;}
  25.                 else if(in < minEven){minEven = in;}
  26.             }else{
  27.                 sumOdd += in;
  28.                 if(in > maxOdd){maxOdd = in;}
  29.                 else if(in < minOdd){minOdd = in;}
  30.             }
  31.         }
  32.         responseVal[0] = sumOdd;
  33.         responseVal[1] = minOdd;
  34.        
  35.         System.out.printf(response, responseVal);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment