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

✍️По всем вопросам: @Pascal4eg
Download Telegram
public class Test {
public static void main(String[] args) {
int i=0;
label1: System.out.print(i++);
if (i < 2) {
goto label1;
}
}
}
🙉6😁3❤1🗿1
Что выведет код? 👆
Anonymous Quiz
41%
012
17%
123
43%
<Ошибка компиляции>
🎉1
import java.util.HashSet;
import java.util.Set;

public class Test {
public static void main(String[] args) {
String str1 = "Hello World";
String str2 = new String("Hello World");

Set<String> set = new HashSet<>();
set.add(str1);
set.add(str2);

for (String str : set) {
if (str == str1) {
System.out.print("origin ");
}
if (str == str2) {
System.out.print("replace ");
}
}
}
}
❤1
Что выведет код? 👆
Anonymous Quiz
31%
origin
11%
replace
57%
origin replace
👍4🎉1
public class Test {
public static void main(String[] args) {
System.out.println(10 + 20 + "30");
}
}
Что выведет код? 👆
Anonymous Quiz
3%
1030
52%
3030
5%
60
19%
102030
21%
<Ошибка компиляции>
👏6🎉2
public class Test {
public static void main(String[] args) {
int i = 5;
boolean b = pri(i++ * 2) && pri(i);
}

public static boolean pri(int i) {
System.out.print(i);
return true;
}
}
❤2
Что выведет код? 👆
Anonymous Quiz
30%
126
33%
105
37%
106
👍2🎉2❤1
public class Test {
public static void main(String[] args) {
int b = oper2() | oper3() & oper4();
System.out.println("-" + b);
}
private static byte oper2() {
System.out.print(2);
return 2;
}
private static byte oper3() {
System.out.print(3);
return 3;
}
private static byte oper4() {
System.out.print(4);
return 4;
}
}
❤3
🎉4
import java.util.ArrayList;
import java.util.List;

class Person {
Long id;
String name;

public Person(Long id, String name) {
this.id = id;
this.name = name;
}

@Override
public boolean equals(Object obj) {
System.out.print(1);
if (obj == this) {
return true;
}
if (obj instanceof Person person) {
return id.equals(person.id);
}
return false;
}
}

public class Test {
public static void main(String[] args) {
List<Person> list = new ArrayList<>();
list.add(new Person(1L, "Leo"));
list.add(new Person(2L, "Raph"));
list.add(new Person(3L, "Donnie"));
list.add(new Person(4L, "Mikey"));

list.contains(new Person(3L, "Shredder"));
}
}
👍1
Что выведет код? 👆
Anonymous Quiz
18%
1
3%
11
31%
111
24%
1111
24%
<Ошибка компиляции>
🎉2
public class Test {
public static void main(String[] args) {
byte b = 50;
print(b);
}
private static void print(Short num) {
System.out.println(num++);
}
}
❤2🔥2
Что выведет код? 👆
Anonymous Quiz
41%
50
30%
51
29%
<Ошибка компиляции>
🎉5❤1
public class Test {
public static void main(String[] args) {
Short b = 50;
inc(b);
System.out.println(b);
}
private static void inc(Short num) {
num++;
}
}
👍2
Что выведет код? 👆
Anonymous Quiz
37%
50
39%
51
24%
<Ошибка компиляции>
❤3👍1🎉1
public class Test {
public static void main(String[] args) {
System.out.println(concat1() < concat2());
}
private static long concat1() {
long start = System.nanoTime();
String s = "";
for (int i = 0; i < 1000; i++) {
s += "-" + i;
}
return System.nanoTime() - start;
}

private static long concat2() {
long start = System.nanoTime();
StringBuilder s = new StringBuilder();
for (int i = 0; i < 1000; i++) {
s.append("-").append(i);
}
return System.nanoTime() - start;
}
}
❤2👍2
Что выведет код? 👆
Anonymous Quiz
44%
true
56%
false
👍5🎉1
public class Test {
public static void main(String[] args) {
System.out.println(calc(10, 5));
}

private static int calc(int i, int j) {
int result = i + j;
return result;

result = i - j;
return result;
}
}
❤3👍3
Что выведет код? 👆
Anonymous Quiz
38%
15
14%
5
48%
<Ошибка компиляции>
🎉3❤2