Advertisement
Guest User

OddEven

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