public class Test {
public static void main(String[] args) {
int x = 5;
int y = 10;
x = x++ + ++y;
System.out.println("x = " + x + ", y = " + y);
}
}❤1🔥1
Что выведет код? 👆
Anonymous Quiz
31%
x = 16, y = 10
53%
x = 16, y = 11
7%
x = 15, y = 11
9%
x = 15, y = 10
🎉4
interface Adder {
int add(int a, int b);
}
interface SmartAdder extends Adder {
int add(double a, double b);
}
interface Nothing {
}❤3
Какой из интерфейсов является функциональным? 👆
Anonymous Quiz
41%
Adder
19%
SmartAdder
13%
Nothing
27%
Ни один из них
👍1🎉1
Какой интерфейс нужно реализовать в классе, чтобы объект этого класса можно было использовать в выражении "for-each" справа?
Anonymous Quiz
14%
Comparable
9%
Serializable
16%
Runnable
61%
Iterate
❤2🎉2
import java.util.Objects;
class Person {
Long id;
String name;
public Person(Long id, String name) {
this.id = id;
this.name = name;
}
public boolean equals(Person other) {
if (other == this) {
return true;
}
return id != null && id.equals(other.id);
}
}
public class Test {
public static void main(String[] args) {
Person person1 = new Person(1L, "John");
Person person2 = new Person(1L, "Jane");
System.out.print(person1.equals(person2));
System.out.print("-");
System.out.print(Objects.equals(person1, person2));
}
}
❤1👍1
🎉2👍1🖕1
public class Test {
public static void main(String[] args) {
int x = 1;
System.out.println("x+1 = " + x+1);
}
}❤🔥1❤1👍1
🎉5
public class Test {
public static void main(String[] args) {
String s = null;
if (s != null & s.length() > 0) {
System.out.println("YES!");
} else {
System.out.println("NO!");
}
}
}❤1👍1
🎉1
public class Test {
public static void main(String[] args) {
int x = 5;
int y = 10;
int result = add(x, y) * multiply(x, y);
System.out.println(result);
}
public static int add(int a, int b) {
try {
return a + b;
} finally {
return a - b;
}
}
public static int multiply(int a, int b) {
try {
return a * b;
} finally {
return a / b;
}
}
}❤1
🎉2
public class Test {
public static void main(String[] args) {
int i = 1;
inc(i);
System.out.println(i);
}
private static void inc(int num) {
num++;
}
}❤2
🎉2
public class Test {
public static void main(String[] args) {
int j = 0;
for (int i = 0; i < 10; i++) {
j = j++;
}
System.out.println(j);
}
}❤5👍1👎1
🎉3🔥2❤1
import java.util.List;
public class Test {
public static void main(String[] args) {
List<Integer> ints = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
ints.stream()
.filter(i -> i % 2 == 0)
.skip(1)
.limit(1)
.forEach(System.out::print);
}
}
❤2
🎉6❤1
public class Test {
public static void main(String[] args) {
int i = Integer.MAX_VALUE;
i++;
if (i == 0) {
System.out.println("ZERO");
} else if (i == Integer.MIN_VALUE) {
System.out.println("MIN");
}
}
}👍3❤2