
Вопрос задан 10.08.2018 в 03:56.
Предмет Информатика.
Спрашивает Просёлова Анастасия.
JAVA Дано число n. С начала суток прошло n минут. Определите, сколько часов и минут будут
показывать электронные часы в этот момент. Программа должна вывести два числа: количество часов (от 0 до 23) и количество минут (от 0 до 59). Учтите, что число n может быть больше, чем количество минут в сутках.

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

Отвечает Ким Костян.
import java.util.Scanner;
/**
* Created by Geek on 20.09.2016.
*/
public class getTime {
public static void main(String[] agrs){
Scanner in = new Scanner(System.in); // Создаем объект ввода через консоль
System.out.print("Сколько минут прошло, после начала дня:");
int n = in.nextInt();
if(n <= 59) {
System.out.print(String.format("Прошло 0 часов и %d минут",n));
} else if(n > 1440) {
n = n - ((n/1440)*1440);
System.out.print(String.format("Прошло %d часиков и %d минут",n/60,n%60));
} else {
System.out.print(String.format("Прошло %d часиков и %d минут",n/60,n%60));
}
}
}
/**
* Created by Geek on 20.09.2016.
*/
public class getTime {
public static void main(String[] agrs){
Scanner in = new Scanner(System.in); // Создаем объект ввода через консоль
System.out.print("Сколько минут прошло, после начала дня:");
int n = in.nextInt();
if(n <= 59) {
System.out.print(String.format("Прошло 0 часов и %d минут",n));
} else if(n > 1440) {
n = n - ((n/1440)*1440);
System.out.print(String.format("Прошло %d часиков и %d минут",n/60,n%60));
} else {
System.out.print(String.format("Прошло %d часиков и %d минут",n/60,n%60));
}
}
}



Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.
Problem Analysis
The problem requires determining the number of hours and minutes displayed on electronic clocks given the number of minutes that have passed since the start of the day. The program should output two numbers: the number of hours (ranging from 0 to 23) and the number of minutes (ranging from 0 to 59). It is important to note that the given number of minutes can be greater than the total number of minutes in a day.Plan
To solve this problem, we can use integer division and modulo operations to calculate the number of hours and minutes. Here is a step-by-step plan: 1. Read the input number of minutes. 2. Calculate the number of hours by performing integer division of the input by 60 (since there are 60 minutes in an hour). 3. Calculate the number of minutes by taking the modulo of the input by 60. 4. Output the calculated number of hours and minutes.Pseudocode
``` 1. Read n (the number of minutes) 2. hours = n // 60 3. minutes = n % 60 4. Output hours and minutes ```Implementation
Here is the implementation of the plan in Java:```java import java.util.Scanner;
public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int hours = n / 60; int minutes = n % 60; System.out.println(hours + " " + minutes); } } ```
Example
Let's say the input is `150`. The program will calculate the number of hours and minutes as follows: - `hours = 150 // 60 = 2` - `minutes = 150 % 60 = 30` So the output will be `2 30`, indicating that the electronic clock will display 2 hours and 30 minutes.Conclusion
In this problem, we used integer division and modulo operations to calculate the number of hours and minutes displayed on electronic clocks given the number of minutes that have passed since the start of the day. The program takes the input number of minutes, performs the necessary calculations, and outputs the number of hours and minutes.

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