Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ForCicleExercise;
- import java.util.Scanner;
- public class OddEvenPosition2 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int n = Integer.parseInt(input.nextLine());
- double numCounter = 0;
- double oddSum = 0;
- double oddMaxNum = -100000000000.0;
- double oddMinNum = 100000000000.0;
- double evenSum = 0;
- double evenMaxNum = -100000000000.0;
- double evenMinNum = 100000000000.0;
- if (n>1) {
- for (int i = 0; i < n; i++) {
- numCounter++;
- double num = Double.parseDouble(input.nextLine());
- if (numCounter % 2 == 0) {
- evenSum = evenSum + num;
- if (evenMaxNum < num) {
- evenMaxNum = num;
- }
- if (evenMinNum > num) {
- evenMinNum = num;
- }
- } else if (numCounter % 2 != 0) {
- oddSum = oddSum + num;
- if (oddMaxNum < num) {
- oddMaxNum = num;
- }
- if (oddMinNum > num) {
- oddMinNum = num;
- }
- }
- }
- System.out.printf("OddSum=%.0f, OddMin=%.0f, OddMax=%.0f, EvenSum=%.0f, EvenMin=%.0f, EvenMax=%.0f", oddSum, oddMinNum, oddMaxNum, evenSum, evenMinNum, evenMaxNum);
- }else if (n==1){
- double n1 = Double.parseDouble(input.nextLine());
- oddSum=n1;
- oddMaxNum=n1;
- oddMinNum=n1;
- System.out.printf("OddSum=%.0f, OddMin=%.0f, OddMax=%.0f, EvenSum=0, EvenMin=No, EvenMax=No",n1,n1,n1);
- } else if (n==0){
- oddSum=0;
- evenSum=0;
- System.out.println("OddSum=0, OddMin=No, OddMax=No, EvenSum=0, EvenMin=No, EvenMax=No");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement