desislava_topuzakova

4. Time After 30 Minutes

Jan 14th, 2024
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. package BasicsOverview;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TimeAfter30Minutes_04 {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. //1. входни данни
  10. int currentHours = Integer.parseInt(scanner.nextLine());
  11. int currentMinutes = Integer.parseInt(scanner.nextLine());
  12.  
  13. //2. изчислявам текущото време в минути
  14. int currentTimeInMinutes = currentHours * 60 + currentMinutes;
  15.  
  16. //3. доабвям 30 минути към текущото време
  17. int timeAfter30Minutes = currentTimeInMinutes + 30;
  18.  
  19. //4. преобразуваме: часове и минути
  20. int endHour = timeAfter30Minutes / 60;
  21. int endMinutes = timeAfter30Minutes % 60;
  22.  
  23. //!!!!
  24. if (endHour == 24) {
  25. endHour = 0;
  26. }
  27.  
  28. //5. отпечатваме -> hh:mm
  29. System.out.printf("%d:%02d", endHour, endMinutes);
  30.  
  31. }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment