Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OddEvenPosition {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- double oddMin = 1000000000.0;
- double oddMax = -1000000000.0;
- double evenMin = 1000000000.0;
- double evenMax = -1000000000.0;
- double oddSum = 0, evenSum = 0;
- for (int i = 1; i <= n; i++) {
- double currentNum = Double.parseDouble(scanner.nextLine());
- if (i % 2 == 1) {
- oddSum += currentNum;
- if (currentNum < oddMin) {
- oddMin = currentNum;
- }
- if (currentNum > oddMax) {
- oddMax = currentNum;
- }
- } else {
- evenSum += currentNum;
- if (currentNum < evenMin) {
- evenMin = currentNum;
- }
- if (currentNum > evenMax) {
- evenMax = currentNum;
- }
- }
- }
- if (n == 0) {
- System.out.println("OddSum=0.00,\nOddMin=No,\nOddMax=No,");
- } else {
- System.out.printf("OddSum=%.2f,\nOddMin=%.2f,\nOddMax=%.2f,\n", oddSum, oddMin, oddMax);
- }
- if (n <= 1) {
- System.out.println("EvenSum=0.00,\nEvenMin=No,\nEvenMax=No");
- } else {
- System.out.printf("EvenSum=%.2f,\nEvenMin=%.2f,\nEvenMax=%.2f\n", evenSum, evenMin, evenMax);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement