public class Task27b public static void main String args throws Interr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
public class Task27b {
public static void main(String[] args) throws InterruptedException {
Scanner scanner = new Scanner(System.in);
System.out.println("Number of :");
int n = scanner.nextInt();
scanner.nextLine();
ArrayList<Thread> arr = new ArrayList<Thread>();
for(int i = 0; i < n; i ++) {
String s = scanner.nextLine();
String b = scanner.nextLine();
String c = "";
int a ;
if(b.charAt(0) != '0') {
if (b.charAt(0) == '+') {
for (int j = 1; j < b.length(); j++) {
c += b.charAt(j);
}
a = Integer.parseInt(c);
} else {
for (int j = 1; j < b.length(); j++) {
c += b.charAt(j);
}
a = Integer.parseInt(c);
a *= -1;
}
}else{
a = 0;
}
Thread t1 = new Thread(new MyThread(s,a));
arr.add(t1);
}
for (Thread c : arr){
c.start();
}
}
}
public class MyThread implements Runnable {
private Thread thread;
private String name;
private int a;
public void join() throws InterruptedException {
thread.join();
}
public int getSum() {
return sum;
}
private int sum = 0;
public MyThread(String name, int a) {
this.name = name;
this.a = a;
}
@Override
public void run() {
for (int i = 0; i < 50000000; i++) {
Calendar calendar = Calendar.getInstance();
int newTime;
if ((calendar.get(Calendar.HOUR_OF_DAY) - 4 + a < 0)) {
newTime = (calendar.get(Calendar.HOUR_OF_DAY) - 4 + a) + 24;
} else {
if ((calendar.get(Calendar.HOUR_OF_DAY) - 4 + a > 24)) {
newTime = (calendar.get(Calendar.HOUR_OF_DAY) - 4 + a) - 24;
} else {
newTime = calendar.get(Calendar.HOUR_OF_DAY) - 4 + a;
}
}
System.out.println(name + " " + newTime + ":" + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}