Advertisement
damesova

Odd Even Position [Mimi][PB]

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