Что выведет код? 👆
Anonymous Quiz
27%
WIN!
36%
LOSE!
17%
<StackOverflowError>
20%
<Ошибка компиляции>
❤2🔥2
public class Test {
public static void main(String[] args) {
int[][] tests = {
{6, 5, 4, 3, 2, 1},
{1, 2},
{1, 2, 3},
{1, 2, 3, 4},
{1}
};
int n = 0;
try {
int i = 0;
while (true) {
if (thirdElementIsThree(tests[i++])) n++;
}
} catch (ArrayIndexOutOfBoundsException e) {
}
System.out.println(n);
}
private static boolean thirdElementIsThree(int[] a) {
return (a.length >= 3) & (a[2] == 3);
}
}❤1
👍4🎉1
public class Test {
public static void main(String[] args) {
int a = 5;
int b = 10;
int result = multiply(a, b);
System.out.println(result);
}
public static int multiply(int x, int y) {
if (y == 0) {
return 0;
} else {
return x + multiply(x, y - 1);
}
}
}🔥2❤1
🎉4❤1
public class Test {
private final String name;
Test(String name) {
this.name = name;
}
private String name() {
return name;
}
private void reproduce() {
new Test("reproduce") {
void printName() {
System.out.println(name());
}
}.printName();
}
public static void main(String[] args) {
new Test("main").reproduce();
}
}❤3🤯2
🎉3👍1
import java.util.List;
import java.util.stream.Stream;
public class Test {
public static void main(String[] args) {
List<String> fruits = Stream.of("orange", "mango").toList();
fruits.add("apple");
System.out.println(fruits);
}
}
👍4❤1
Что выведет код? 👆
Anonymous Quiz
7%
[orange, mango]
60%
[orange, mango, apple]
28%
<Ошибка UnsupportedOperationException>
5%
<Ошибка компиляции>
❤4🎉1
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Test {
public static void main(String[] args) {
Set<String> fruits = Stream.of("Apple", "Pear", "Banana").collect(Collectors.toSet());
fruits.add("pear");
fruits.add("Banana");
System.out.println(fruits.size());
}
}
❤3
👍2🎉1
Что такое Lambda-выражение?
Anonymous Quiz
9%
Ссылка на метод
13%
Математическое выражение
23%
Функциональный интерфейс
55%
Простой способ описывать анонимные функции
👍3❤1🎉1
public class Null {
public static void greet() {
System.out.println("HI!");
}
public static void main(String[] args) {
((Null) null).greet();
}
}❤2👍1
👍3❤1🎉1
public class Test {
static {
main(new String[] { "Hello" });
}
public static void main(String[] args) {
System.out.print("Hi");
}
}❤1
Что выведет код? 👆
Anonymous Quiz
34%
HelloHi
24%
HiHi
15%
<StackOverflowError>
27%
<Ошибка компиляции>
👍4🎉1💊1
public class Test {
public static void main(String[] args) {
Boolean b;
System.out.println(Boolean.TRUE.equals(!b));
}
}❤2
🎉3
enum Month {
JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER
}
public class Test {
public static void main(String[] args) {
Month m = Month.JANUARY;
String season = switch (m) {
case DECEMBER, JANUARY, FEBRUARY -> "Winter";
case MARCH, APRIL, MAY -> "Spring";
case JUNE, JULY, AUGUST -> "Summer";
case SEPTEMBER, OCTOBER -> "Autumn";
};
System.out.println(season);
}
}❤5
🎉4