Advertisement
AngelKejov

Untitled

Apr 2nd, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. package Exersices;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class OddEvenPosition {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.  
  10.         int n = Integer.parseInt(sc.nextLine());
  11.  
  12.         double oddSum = 0;
  13.         double oddMin = Double.MAX_VALUE;
  14.         double oddMax = Double.MIN_VALUE;
  15.         double evenSum = 0;
  16.         double evenMin = Double.MAX_VALUE;
  17.         double evenMax = Double.MIN_VALUE;
  18.         for (int i = 0; i < n; i++) {
  19.             double numbers = Double.parseDouble(sc.nextLine());
  20.  
  21.             if (numbers % 2 != 0) {
  22.                 oddSum += numbers;
  23.                 if (numbers < oddMin) {
  24.                     oddMin = numbers;
  25.                 } else if (numbers > oddMax) {
  26.                     oddMax = numbers;
  27.                 }
  28.             } else {
  29.                 evenSum += numbers;
  30.  
  31.                 if (numbers < evenMin) {
  32.                     evenMin = numbers;
  33.                 } else if (numbers > evenMax) {
  34.                     evenMax = numbers;
  35.                 }
  36.             }
  37.         }
  38.  
  39.         if (n == 0) {
  40.             System.out.printf("OddSum=0.00,\nOddMin=No,\nOddMax=No" +
  41.                     "\nEvenSum=0.00,\nEvenMin=No,\nEvenMax=No");
  42.         } else if (n == 1) {
  43.             System.out.printf("OddSum=%.2f,\nOddMin=%.2f,\nOddMax=%.2f," +
  44.                     "\nEvenSum=0.00,\nEvenMin=no,\nEvenMax=no", oddSum, oddMin, oddMax);
  45.         } else {
  46.             System.out.printf("OddSum=%.2f," +
  47.                     "\nOddMin=%.2f,\nOddMax=%.2f,\n", oddSum, oddMin, oddMax);
  48.             System.out.printf("EvenSum=%.2f,\nEvenMin=%.2f,\nEvenMax=%.2f",
  49.                     evenSum, evenMin, evenMax);
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement