/
Valeriia87
/
homeWork_3
Обзор
Документация
Войти
/
Valeriia87
/
homeWork_3
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Hw3.java
34 строки
1 KB
Valeriia87
create: Hw3.java
04 апр 2026, 17:23
Верифицирован
04 апр 2026, 17:23
abd8e92
Код
Авторство
О чём код?
//The programme asks for the year and the number of days in it, checks and counts the number of correct ones import java.util.Scanner; public class Hw3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int score = 0; // Variable for storing correct answers while (true) { //The loop continues as long as the entered values are correct. System.out.println("Введите год в формате yyyy"); int year = scanner.nextInt(); System.out.println("Введите количество дней этого года в формате ddd"); int days = scanner.nextInt(); int correctDays; if (year % 400 == 0) { //calculation of the number of days in a year correctDays = 366; } else if (year % 100 == 0) { correctDays = 365; } else if (year % 4 == 0) { correctDays = 366; } else { correctDays = 365; } if (days == correctDays) { //comparison of the correct answer with the user's answers score++; } else { System.out.println("Неправильно! Верное количество дней " + correctDays); System.out.println("Набрано очков:" + score); break; } } } }