MoPhreak

Untitled

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