👩💻 Викторина: что выведет код?
public class Main {
static int x = 0;
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(() -> {
for (int i = 0; i < 1000; i++) x++;
});
Thread t2 = new Thread(() -> {
for (int i = 0; i < 1000; i++) x++;
});
t1.start();
t2.start();
Thread.sleep(100);
System.out.print(x);
}
}
➡️ Easy Java | #Викторина
public class Main {
static int x = 0;
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(() -> {
for (int i = 0; i < 1000; i++) x++;
});
Thread t2 = new Thread(() -> {
for (int i = 0; i < 1000; i++) x++;
});
t1.start();
t2.start();
Thread.sleep(100);
System.out.print(x);
}
}
➡️ Easy Java | #Викторина