Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package e_SimpleLoops;
- import java.util.Scanner;
- public class p11_OddAndEvenPositionMY {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int count = Integer.parseInt(scan.nextLine());
- double oddSum = 0;
- double oddMax = -1000000000.0;
- double oddMin = 1000000000.0;
- double evenSum = 0;
- double evenMax = -1000000000.0;
- double evenMin = 1000000000.0;
- for (int i = 1; i <= count; i++) {
- double currentNum = Double.parseDouble(scan.nextLine());
- if (i % 2 == 0) {
- evenSum += currentNum;
- if (currentNum > evenMax) {
- evenMax = currentNum;
- }
- if (currentNum < evenMin) {
- evenMin = currentNum;
- }
- } else {
- oddSum += currentNum;
- if (currentNum > oddMax) {
- oddMax = currentNum;
- }
- if (currentNum < oddMin) {
- oddMin = currentNum;
- }
- }
- }
- if (oddSum % 1 == 0.0) {
- System.out.printf("OddSum=%s,%n", Integer.toString((int)oddSum));
- } else {
- System.out.printf("OddSum=%s,%n", Double.toString(oddSum));
- }
- if (oddMin == 1000000000.0) {
- System.out.println("OddMin=No,");
- } else if (oddMin % 1 == 0.0) {
- System.out.printf("OddMin=%s,%n", Integer.toString((int)oddMin));
- } else {
- System.out.printf("OddMin=%s,%n", Double.toString(oddMin));
- }
- if (oddMax == -1000000000.0) {
- System.out.println("OddMax=No,");
- } else if (oddMax % 1 == 0.0) {
- System.out.printf("OddMax=%s,%n", Integer.toString((int)oddMax));
- } else {
- System.out.printf("OddMax=%s,%n", Double.toString(oddMax));
- }
- if (evenSum % 1 == 0.0) {
- System.out.printf("EvenSum=%s,%n", Integer.toString((int)evenSum));
- } else {
- System.out.printf("EvenSum=%s,%n", Double.toString(evenSum));
- }
- if (evenMin == 1000000000.0) {
- System.out.println("EvenMin=No,");
- } else if (evenMin % 1 == 0.0) {
- System.out.printf("EvenMin=%s,%n", Integer.toString((int)evenMin));
- } else {
- System.out.printf("EvenMin=%s,%n", Double.toString(evenMin));
- }
- if (evenMax == -1000000000.0) {
- System.out.println("EvenMax=No,");
- } else if (evenMax % 1 == 0.0) {
- System.out.printf("EvenMax=%s,%n", Integer.toString((int)evenMax));
- } else {
- System.out.printf("EvenMax=%s,%n", Double.toString(evenMax));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement