Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- 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 oddSum = 0.0;
- double oddMin = 1000000000.0;
- double oddMax = -1000000000.0;
- double evenSum = 0.0;
- double evenMin = 1000000000.0;
- double evenMax = -1000000000.0;
- DecimalFormat df = new DecimalFormat("#.##");
- for (int i = 1; i <= n; i++) {
- double num = Double.parseDouble(scanner.nextLine());
- if (i % 2 != 0) {
- oddSum += num;
- if (num < oddMin) {
- oddMin = num;
- }
- if (num > oddMax) {
- oddMax = num;
- }
- } else {
- evenSum += num;
- if (num < evenMin) {
- evenMin = num;
- }
- if (num > evenMax) {
- evenMax = num;
- }
- }
- }
- System.out.println("OddSum=" + df.format(oddSum) + ",");
- if (oddMin == 1000000000.0) {
- System.out.println("OddMin=No,");
- } else {
- System.out.println("OddMin=" + df.format(oddMin) + ",");
- }
- if (oddMax == -1000000000.0) {
- System.out.println("OddMax=No,");
- } else {
- System.out.println("OddMax=" + df.format(oddMax) + ",");
- }
- System.out.println("EvenSum=" + df.format(evenSum) + ",");
- if (evenMin == 1000000000.0) {
- System.out.println("EvenMin=No,");
- } else {
- System.out.println("EvenMin=" + df.format(evenMin) + ",");
- }
- if (evenMax == -1000000000.0) {
- System.out.print("EvenMax=No");
- } else {
- System.out.print("EvenMax=" + df.format(evenMax));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement