Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.helloworld;
- import java.util.Scanner;
- public class HelloWorld {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.println("Інтервал: ");
- int z = 0, maxn = 0, maxp = 0, i = 0, sum = 0, b = 0; double d = 0, a = 0, v = 0;
- int x = in.nextInt();
- int y = in.nextInt();
- System.out.print("Непарні за зростанням: ");
- for (i = x; i <= y; i++) {
- if (i % 2 != 0) {
- System.out.printf("%d ", i);
- z += i;
- if (i > maxn) {
- maxn = i;
- }
- }
- }
- System.out.printf("\nНайбільше непарне: %d", maxn);
- System.out.printf("\nСума %d", z);
- z = 0;
- System.out.print("\nПарні за спаданням: ");
- for (i = y; i >= x; i--) {
- if (i % 2 == 0) {
- System.out.printf("%d ", i);
- z += i;
- if (i > maxp) {
- maxp = i;
- }
- }
- }
- System.out.printf("\nНайбільше парне: %d", maxp);
- System.out.printf("\nСума %d", z);
- System.out.print("\nВведіть довжину ряду Фібоначчі:");
- d = in.nextDouble();
- System.out.print("\n");
- if (maxn % 2 == 0) {
- a++;
- }
- if (maxp % 2 == 0) { //ТУТ ОШИБКА
- a++;
- }
- System.out.printf("%d %d ", maxn, maxp);
- i = 0;
- do {
- sum = maxn + maxp;
- maxn = maxp; maxp = sum;
- System.out.printf("%d ", sum);
- if (sum % 2 == 0) {
- a++;
- }
- i++;
- } while (i != d - 2);
- v = a / d * 100;
- System.out.printf("\nВідсоток парних: %.2f%%", v);
- v = (d - a) / d * 100;
- System.out.printf("\nВідсоток непарних: %.2f%%", v);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement