
Составить расписание звонков уроков. Пользователь вводит номер уpока, программа выдает время урока.
Используйте оператор множество выбора switch

Ответы на вопрос

Function getTime(lesson)
{
var times = [];
times.push("8.30");
times.push("9.10");
times.push("10.20");
times.push("11.35");
times.push("12.25");
times.push("13.15");
switch (lesson)
{
case 1: return times[0];
case 2: return times[1];
case 3: return times[2];
case 4: return times[3];
case 5: return times[4];
case 6: return times[5];
default: return "Нет урока.";
}
}



Creating a School Bell Schedule Program
To create a program that provides the time for each lesson based on the input lesson number, we can use a switch statement to handle different cases. Here's a breakdown of the program:
1. Input Lesson Number: - The user will input the lesson number. 2. Using Switch Statement: - We'll use a switch statement to handle different cases for each lesson number and provide the corresponding time for the lesson.
3. Output: - The program will output the time for the specified lesson.
Let's proceed with the implementation using the provided information.
Using Switch Statement for Lesson Time Lookup
```java // Assuming the user input is stored in a variable called lessonNumber int lessonNumber = /* user input */;
// Using a switch statement to handle different cases for lesson numbers switch (lessonNumber) { case 1: System.out.println("Lesson 1: 8:00 - 8:45"); break; case 2: System.out.println("Lesson 2: 8:50 - 9:35"); break; case 3: System.out.println("Lesson 3: 9:40 - 10:25"); break; // Add cases for other lessons as per the schedule default: System.out.println("Invalid lesson number"); } ```
In this example, the program takes the user input for the lesson number and uses a switch statement to match the input with the corresponding lesson time. If the input matches a case, the program outputs the time for that lesson. If the input doesn't match any case, it outputs "Invalid lesson number."
This approach allows for easy lookup of lesson times based on the lesson number provided by the user.
Feel free to modify the code to include the complete schedule based on the provided information.


Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili