Advertisement
Asmund_11

Untitled

Oct 21st, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. package com.example.helloworld;
  2. import java.util.Scanner;
  3.  
  4. public class HelloWorld {
  5.     public static void main(String[] args) {
  6.         Scanner in = new Scanner(System.in);
  7.         System.out.println("Інтервал: ");
  8.         int z = 0, maxn = 0, maxp = 0, i = 0, sum = 0, b = 0; double d = 0, a = 0, v = 0;
  9.         int x = in.nextInt();
  10.         int y = in.nextInt();
  11.         System.out.print("Непарні за зростанням: ");
  12.         for (i = x; i <= y; i++) {
  13.             if (i % 2 != 0) {
  14.                 System.out.printf("%d ", i);
  15.                 z += i;
  16.                 if (i > maxn) {
  17.                     maxn = i;
  18.                 }
  19.             }
  20.         }
  21.         System.out.printf("\nНайбільше непарне: %d", maxn);
  22.         System.out.printf("\nСума %d", z);
  23.         z = 0;
  24.         System.out.print("\nПарні за спаданням: ");
  25.         for (i = y; i >= x; i--) {
  26.             if (i % 2 == 0) {
  27.                 System.out.printf("%d ", i);
  28.                 z += i;
  29.                 if (i > maxp) {
  30.                     maxp = i;
  31.                 }
  32.             }
  33.         }
  34.         System.out.printf("\nНайбільше парне: %d", maxp);
  35.         System.out.printf("\nСума %d", z);
  36.         System.out.print("\nВведіть довжину ряду Фібоначчі:");
  37.         d = in.nextDouble();
  38.         System.out.print("\n");
  39.         if (maxn % 2 == 0) {
  40.             a++;
  41.         }
  42.         if (maxp % 2 == 0) {   //ТУТ ОШИБКА
  43.             a++;
  44.         }
  45.         System.out.printf("%d %d ", maxn, maxp);
  46.         i = 0;
  47.         do {
  48.             sum = maxn + maxp;
  49.             maxn = maxp; maxp = sum;
  50.             System.out.printf("%d ", sum);
  51.             if (sum % 2 == 0) {
  52.                 a++;
  53.             }
  54.             i++;
  55.         } while (i != d - 2);
  56.         v = a / d * 100;
  57.         System.out.printf("\nВідсоток парних: %.2f%%", v);
  58.         v = (d - a) / d * 100;
  59.         System.out.printf("\nВідсоток непарних: %.2f%%", v);
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement