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