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