Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //11. Четни / нечетни позиции
- public class MyClass {
- public static void main(String args[]) {
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- int numberCount = scanner.nextInt();
- double minNeutralValue = 1111111110.0;
- double maxNeutralValue = -1111111110.0;
- double oddSum = 0.0;
- double oddMin = minNeutralValue;
- double oddMax = maxNeutralValue;
- double evenSum = 0.0;
- double evenMin = minNeutralValue;
- double evenMax = maxNeutralValue;
- double num = 0.0;
- for (int i = 1; i <= numberCount; i++) {
- num = scanner.nextDouble();
- if (i % 2 == 0) {
- evenSum += num;
- if (num <= evenMin) {
- evenMin = num;
- }
- if (num >= evenMax) {
- evenMax = num;
- }
- } else {
- oddSum += num;
- if (num <= oddMin) {
- oddMin = num;
- }
- if (num >= oddMax) {
- oddMax = num;
- }
- }
- }
- System.out.printf("OddSum=%.2f,\n",oddSum);
- if (oddMin == minNeutralValue) {
- System.out.print("OddMin=No\n");
- } else {
- System.out.printf("OddMin=%.2f,\n",oddMin);
- }
- if (oddMax == maxNeutralValue) {
- System.out.print("OddMax=No,\n");
- } else {
- System.out.printf("OddMax=%.2f,\n",oddMax);
- }
- System.out.printf("EvenSum=%.2f,\n",evenSum);
- if (evenMin == minNeutralValue) {
- System.out.print("EvenMin=No,\n");
- } else {
- System.out.printf("EvenMin=%.2f,\n",evenMin);
- }
- if (evenMax == maxNeutralValue) {
- System.out.print("EvenMax=No\n");
- } else {
- System.out.printf("EvenMax=%.2f",evenMax);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement