Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public class Solution {
  2. public static volatile boolean isStopped = false;
  3.  
  4. public static void main(String[] args) throws InterruptedException {
  5. Clock clock = new Clock("Лондон", 23, 59, 57);
  6. Thread.sleep(4000);
  7. isStopped = true;
  8. Thread.sleep(1000);
  9. }
  10.  
  11. public static class Clock extends Thread {
  12. private String cityName;
  13. private int hours;
  14. private int minutes;
  15. private int seconds;
  16.  
  17. public Clock(String cityName, int hours, int minutes, int seconds) {
  18. this.cityName = cityName;
  19. this.hours = hours;
  20. this.minutes = minutes;
  21. this.seconds = seconds;
  22. start();
  23. }
  24.  
  25. public void run() {
  26. try {
  27. while (!isStopped) {
  28. printTime();
  29. }
  30. } catch (InterruptedException e) {
  31. }
  32. }
  33.  
  34.  
  35. private void printTime() throws InterruptedException {
  36. //add your code here - добавь код тут
  37. Thread.sleep(1000);
  38. seconds+=1;
  39. if(hours==23&& minutes ==59 && seconds==60){
  40. hours=0; minutes=0; seconds=0;
  41. }else if(seconds ==60){
  42. seconds=0;
  43. minutes+=1;
  44. if(minutes==60){
  45. seconds=0;
  46. minutes=0;
  47. hours+=1;
  48. }
  49.  
  50. }
  51.  
  52.  
  53. if (hours == 0 && minutes == 0 && seconds == 0) {
  54. System.out.println(String.format("В г. %s сейчас полночь!", cityName));
  55. } else {
  56. System.out.println(String.format("В г. %s сейчас %d:%d:%d!", cityName, hours, minutes, seconds));
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement