Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tasks;
- import java.util.Scanner;
- public class Task_02 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("n = ");
- int n = Integer.parseInt(scanner.nextLine());
- System.out.println("Enter the numbers: ");
- double oddSum = 0.00;
- double oddMin = 1000000000.0;
- double oddMax = -1000000000.0;
- double evenSum = 0.00;
- double evenMin = 1000000000.0;
- double evenMax = -1000000000.0;
- 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;
- }
- }
- }
- if (oddMin == 1000000000.0) {
- System.out.printf("OddSum=%.0f, %nOddMin=No, %nOddMax=No,", oddSum);
- } else if (oddSum % 1 == 0) {
- System.out.printf("OddSum=%.0f, %nOddMin=%.0f, %nOddMax=%.0f,",
- oddSum, oddMin, oddMax);
- } else {
- System.out.printf("OddSum=%.1f, %nOddMin=%.1f, %nOddMax=%.1f,",
- oddSum, oddMin, oddMax);
- }
- if (evenMin == 1000000000.0) {
- System.out.printf("%nEvenSum=%.0f, %nEvenMin=No, %nEvenMax=No", evenSum);
- } else if (evenSum % 1 == 0) {
- System.out.printf("%nEvenSum=%.0f, %nEvenMin=%.0f, %nEvenMax=%.0f", evenSum, evenMin, evenMax);
- } else {
- System.out.printf("%nEvenSum=%.1f %nEvenMin=%.1f, %nEvenMax=%.1f", evenSum, evenMin, evenMax);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement