Java | Tests
1.82K subscribers
1 photo
1 link
Проверь свои знания в Java

✍️По всем вопросам: @Pascal4eg
Download Telegram
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
Что выведет код? 👆
Anonymous Quiz
16%
<ничего>
26%
2468
44%
4
13%
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
🎉2❤1
public class Test {
public static final int END = Integer.MAX_VALUE;
public static final int START = END - 100;

public static void main(String[] args) {
int count = 0;
for (int i = START; i <= END; i++) count++;
System.out.println(count);
}
}
❤3
🎉5
public class Test {
public static void main(String[] args) {
int minutes = 0;
for (int ms = 0; ms < 60 * 60 * 1000; ms++) {
if (ms % 60 * 1000 == 0) {
minutes++;
}
}
System.out.println(minutes);
}
}
❤3
Что выведет код? 👆
Anonymous Quiz
38%
60
34%
60000
28%
3600000
👍4❤1🎉1
public class Test {
public static void main(String[] args) {
Integer a = 128;
Integer b = 128;
System.out.print(a == b);

System.out.print("-");

Integer x = 1;
Integer y = 1;
System.out.print(x == y);
}
}
❤4
Что выведет код? 👆
Anonymous Quiz
47%
true-true
5%
true-false
30%
false-true
18%
false-false
❤2🔥1
public class Test {
private Test internalInstance = new Test();

public Test() throws Exception {
throw new Exception("I'm not coming out");
}

public static void main(String[] args) {
try {
Test b = new Test();
System.out.println("WIN!");
} catch (Exception ex) {
System.out.println("LOSE!");
}
}
}
❤2
❤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
Что выведет код? 👆
Anonymous Quiz
49%
50
14%
5
5%
10
31%
<Бесконечная рекурсия>
🎉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
Что выведет код? 👆
Anonymous Quiz
29%
reproduce
31%
main
40%
<Ошибка компиляции>
🎉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
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