/
Scaramoushe
/
HW3_Task2
Обзор
Документация
Войти
/
Scaramoushe
/
HW3_Task2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Task2.java
56 строк
2 KB
Scaramoushe
Create: Task2.java
01 июл 2026, 18:35
Верифицирован
01 июл 2026, 18:35
dd8e205
Код
Авторство
О чём код?
import java.util.Scanner; public class Task2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = 0; while(true) { int year = readInt(sc, "Введите год: "); int days = readInt(sc, "Введите количество дней:"); int actualDays = getDaysInYear(year); if (actualDays != days) { System.out.println("Неправильно! В этом году " + actualDays + " дней!"); break; } count++; } System.out.println("Набрано очков: " + count); } private static int getDaysInYear(int year) { if (isLeapYear(year)) { return 366; } else { return 365; } } private static boolean isLeapYear(int year) { if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0 ) { return true; } else { return false; } } private static int readInt(Scanner sc, String message) { int value = 0; do { System.out.println(message); if (!sc.hasNextInt()) { System.out.println("Вы ввели не целое число!"); sc.next(); value = -1; } else { value = sc.nextInt(); if (value < 0) { System.out.println("Значение не может быть отрицательным!"); } } } while (value < 0); return value; } }