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
❤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
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
🎉3❤2
public class Test {
public final int value = 4;
public void doIt() {
int value = 6;
Runnable r = new Runnable() {
public final int value = 8;
public void run() {
int value = 10;
System.out.println(this.value);
}
};
r.run();
}
public static void main(String[] args) {
new Test().doIt();
}
}❤1
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Test {
public static void main(String[] args) {
List<String> list = Stream.of("Pizza", "Sushi", "Pasta", "Sushi", "Pizza")
.sequential()
.filter(new TreeSet<>()::add)
.collect(Collectors.toList());
System.out.println(list);
}
}
👍2❤1🔥1
Что выведет код? 👆
Anonymous Quiz
27%
[Pizza, Sushi, Pasta, Sushi, Pizza]
54%
[Pizza, Sushi, Pasta]
19%
<Ошибка компиляции>
👍5❤2👀2🎉1
public class Test {
public static void main(String[] args) {
int x = 5;
int y = 8;
if (x++ > 5 && ++y > 8 ) {
x++;
}
System.out.println("x = " + x + ", y = " + y);
}
}❤2👍2
Что выведет код? 👆
Anonymous Quiz
18%
x = 7, y = 9
33%
x = 6, y = 9
41%
x = 6, y = 8
8%
x = 7, y = 8
❤5👍3🎉3
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