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);
- String pattern = "###0.00";
- DecimalFormat df = new DecimalFormat(pattern);
- int n = Integer.parseInt(scanner.nextLine());
- double sumEvenNums = 0;
- double sumOddNums = 0;
- double maxEven = -1000000000.0;
- double minEven = 1000000000.0;
- double maxOdd = -1000000001.0;
- double minOdd = 1000000001.0;
- for (int i = 1; i <= n; i++) {
- double currentNum = Double.parseDouble(scanner.nextLine());
- if (i % 2 == 0) {
- sumEvenNums += currentNum;
- if (currentNum > maxEven) {
- maxEven = currentNum;
- }
- if (currentNum < minEven) {
- minEven = currentNum;
- }
- } else {
- sumOddNums += currentNum;
- if (currentNum > maxOdd) {
- maxOdd = currentNum;
- }
- if (currentNum < minOdd) {
- minOdd = currentNum;
- }
- }
- }
- System.out.println("OddSum=" + df.format(sumOddNums) + ",");
- if (minOdd == 1000000001.0) {
- System.out.println("OddMin=No"+ ",");
- } else {
- System.out.println("OddMin=" + df.format(minOdd)+ ",");
- }
- if (maxOdd == -1000000001.0) {
- System.out.println("OddMax=No"+ ",");
- } else {
- System.out.println("OddMax=" + df.format(maxOdd)+ ",");
- }
- System.out.println("EvenSum=" + df.format(sumEvenNums)+ ",");
- if (minEven == 1000000000.0) {
- System.out.println("EvenMin=No"+ ",");
- } else {
- System.out.println("EvenMin=" + df.format(minEven)+ ",");
- }
- if (maxEven == -1000000000.0) {
- System.out.println("EvenMax=No");
- } else {
- System.out.println("EvenMax=" + df.format(maxEven));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement